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?
Yes.
the last one
just a text replacement
It is performed by a preprocessing pass. Some good details can be found here
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.
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With