Examples of compiler tricks

Let's start with something fun, to show you that compilers are really clever. Unfortunately, you can often hear that compilers are dumb, but you shouldn't believe that. In ancient times, compilers were dumb and there was a difference in writing ++x instead of x = x +1 as they resulted in different PDP-11 instructions. But not anymore. Let me convince you with some examples of compiler cleverness.

We will start with simple summation. But, in order to check what the compiler really makes out of our code, we need yet another performance tool which we didn't mention in Chapter 2Profiling to Find Bottlenecks— the Compiler Explorer by Matt Godbold. In order to use it, you just go to https://godbolt.org and paste your ...

Get Hands-On High Performance Programming with Qt 5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.