Preprocessor

S

sangeeta chowdhary

Hi,

I am using macro in my code,and I am using GCC compiler.
I want to see expanded file ,I want to see how macro is expanded
in my code by preprocessor before compilation.
Is there any command for it?
 
R

Rob Kendrick

I am using macro in my code,and I am using GCC compiler.
I want to see expanded file ,I want to see how macro is expanded
in my code by preprocessor before compilation.
Is there any command for it?

You want "-E". See `man gcc`.

B.
 
S

sangeeta chowdhary

Sometimes you can use the xstr macro,
which I copied from the C standard.
Though I have heard that sometimes,
implementation macros may contain characters
which render them unprintable this way.

/* BEGIN new.c */

#include <stdio.h>

#define str(s)      # s
#define xstr(s)     str(s)

int main(void)
{

#ifdef putchar
    puts("The putchar macro looks like this:\n\n"
        "#define putchar(X) \\");
    puts(xstr(putchar(X)));
#else
    puts("putchar is not a macro on this implementation");
#endif

    return 0;

}

/* END new.c */

Thanks Sir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top