Where are macros stored?

人盡茶涼 提交于 2019-12-07 05:53:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!