I am reading effective c++. When it comes to Item 2 (prefer const, enum, and inline to #define), Scott says: #define is often treated as if it’s not part of the language, and it may be removed by the preprocessor before the source code gets to a complier.
Can anyone show me an example about this ? thanks.
That’s a somewhat fuzzy statement, but formally the preprocessor is a separate phase of compilation, and back in the olden days the preprocessor was a separate program that did its thing before the compiler got to see the code. Most compilers have an option to only do the preprocessing, which is sometimes helpful for figuring out where some code has gone astray. But under the “as if” rule, the compiler doesn’t have to do preprocessing in a separate phase; it just has to produce the same result as if it had done that.