I am reading Efficient c++ (older version) and have some doubts.
Here, for example, it says:
When you do something like this
#define ASPECT_RATIO 1.653the symbolic name ASPECT_RATIO may never be seen by the compilers; it may be removed by the preprocessors before the source code ever gets compiled. As a results the ASPECT_RATIO may never get entered to SYMBOLIC_TABLE. It an be confusing if you get an error during compilation involving the constant, because the error message may refer to 1.653 and not ASPECT_RATIO
I don’t understand this paragraph.How can anything be removed the preprocessor, just like that. what could be the reasons and how feasible are they in real world.
Thanks
Basically what it describes is exactly how C and C++ pre-processor works. The reason is to replace macros/constants (that are made using the
#definedirective) with their actual values, instead of repeating the same values over and over again. In C++ it is considered a bad style using C-style macros, but they’re supported for C compatibility.The preprocessor, as the name suggests, runs prior to the actual compilation, and is basically changing the source code as directed through the pre-processor directives (those starting with
#). This also includes replacement of the macros with their values, the inclusion of the header files as directed by the#includedirective, etc etc.This is used in order to avoid code repetitions, magic numbers, to share interfaces (header files) and many other useful things.