Search This Blog

Sunday, November 8, 2009

Macro expansion output using Visual C++ 6.0

I like this option of Visual studio very much. I forgot this for long time. I have tested this option for Visual C++ 6.0 but I am 99% sure that it must be working for all new versions of visual studio.

Suppose I have simple program like
// Souce.c
#define greater(a, b) ((a) > (b) ? a : b);

int main()
{
greater(10, 20);

return 0;
}
// Source.c ends here

Now how to create a file which will show me expanded macros in this course file?

Very simple add /E and /P to project options. In the same file as that of Source.c a new file Source.i will be generated.

I am writing here contents of Source.i to understand it's contents -

# Source.i

#line 1 ...



int main()
{
((10) > (20) ? 10 : 20);;

return 0;
}

# Source.i ends here

Hope this post is of help

2 comments:

  1. I just checked with Visual studio 2008.

    Go to Project (Menu) -> select properties.
    This will open one options window.
    On Right hand side there is tree -
    Expand confugeration properties
    Expand C/C++ (under configeration properties)
    Select Command Line (Under C/C++)

    On right side it shows "All options"
    and below it "Additional Options"
    Add /E /P in "Additional Options" text field.

    ReplyDelete
  2. This is interesting.. I like Visual studio for all these options it provides.

    ReplyDelete