The program-build process is equivalent to the following:
- First the preprocessor translates your source and header files into an intermediate file.
- Then the compiler translates that intermediate file into an object file.
- Then the linker combines one or more object files and object libraries into an executable file.
- Sometime later, you run the executable file.
A particular compiler implementation might not generate all of these intermediate files, but it will act as if it did. Some compilers can be induced to preserve the intermediate file produced by the preprocessor so you can look at it.
The "scope" of a preprocessor macro (it is not a variable) is all of the lines between its #define and its #undef. The things that affect variable scope (such as function definitions and braces) have no effect on preprocessor macros.
You expected execution of function
foo to change the value of macro
a. In actuality, all of the preprocessor directives and macros have been fully expanded before the code is compiled. The compiler and executable have no awareness that there is such a thing as a preprocessor.