January 2020
Intermediate to advanced
454 pages
11h 25m
English
Sometimes, we wish to change the behavior of our programs but the code that we are creating is always constant, meaning the compiler is capable of determining the value of the branch itself, as shown in this example:
if (!NDEBUG) {}
This is a common if statement used in a lot of code, including the standard library. If debugging is enabled, this code evaluates to true. We use this by adding debug statements to our code, which can be turned off. The compiler is smart enough to see that NDEBUG is true or false and will either add the code or remove the code completely. In other words, the compiler can make a simple optimization and reduce the size of the code as well as remove an unneeded branch as it knows the value of this ...