Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro effect in the code

Tags:

c

suppose I have a macro, like

#define max(a,b) (((a) > (b)) ? (a) : (b))

then I use it in the "normal code"

int foo()
{
...
c = max(a,b);
...
}

Is there a way to see the code after precompiling? Does exist a way to see the effect of macro substituion (maybe done by compiler, I use gcc)?

I'd like to get something like this:

int foo()
{
...
c = ((a>b) ? a : b);
...
}

Is there something like this?

like image 417
the_candyman Avatar asked Apr 04 '11 09:04

the_candyman


2 Answers

You want to see the preprocessed source code. Usually your C compiler has a switch to output the preprocessed output.

For gcc, it's gcc -E [C-filename].

For msvc, it's cl /EP or cl /P. See MSVC /P (Preprocess to a File)

like image 131
typo.pl Avatar answered Oct 14 '22 17:10

typo.pl


Use cpp, the GCC C preprocessor.

gcc is only a collection of tools: cpp, cc and ld for examples.

like image 31
Benoit Avatar answered Oct 14 '22 17:10

Benoit