问题
If I use macros in my C code, such as
#define var 10
then where exactly are the stored in the space allocated to the process by the kernel? In heap or BSS or global data? Or is it just a text replacement for var in one of the compiler passes?
回答1:
Yes.
the last one
just a text replacement
It is performed by a preprocessing pass. Some good details can be found here
回答2:
Preprocessor directives like #define
are replaced with the corresponding text during the preprocessing phase of compilation, and are (almost) never represented in the final executable.
回答3:
"Macros" are a "compile time thing".
It just "replaces the text" that the compiler sees - before it compiles.
The result (in the compiled code) can be a set of operations ... a data declaration ... or nothing at all.
But the "macro" itself is Ancient History after the preprocessor finishes, and before compilation actually begins.
回答4:
Macros are merely text replacements. When substituted, these become a part of the code and are thus stored in CODE SEGMENT.
回答5:
It's an instruction to the compiler, and thus is stored in tables in the compiler's process space, not your code's space .
来源:https://stackoverflow.com/questions/10825421/where-are-macros-stored