Discussion: Off to a Good Start
Explore how C++ handles the order of function argument evaluation and its impact on program execution. Learn to identify when function calls depend on each other's order and how to write code that avoids unexpected behaviors caused by unspecified evaluation order.
We'll cover the following...
Run the code
Now, it’s time to execute the code and observe the output.
Understanding the output
In this puzzle, we want to start a program that relies on a logger having been set up and a configuration having been read. As long as both of those are done before the program starts, we’re good. The order in which the logger is set up and the configuration is read doesn’t seem to matter here, but what if it did? What if, for instance, initializing the logger sets up some global logger instance that we use while reading the configuration? Can we rely on the two functions being called in the order listed in the program? Unfortunately, we can’t since the evaluation order of function argument expressions is unspecified. ...