Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are macros stored?

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?

like image 689
Recker Avatar asked May 30 '12 22:05

Recker


3 Answers

Yes.
the last one

just a text replacement

It is performed by a preprocessing pass. Some good details can be found here

like image 168
EvilTeach Avatar answered Nov 07 '22 11:11

EvilTeach


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.

like image 23
Jonathan Callen Avatar answered Nov 07 '22 12:11

Jonathan Callen


"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.

like image 3
paulsm4 Avatar answered Nov 07 '22 11:11

paulsm4