Compile error within code in #ifndef  
Author Message
JDC457880





PostPosted: Visual C++ Language, Compile error within code in #ifndef Top

This is probably just me missing something obvious, but ....

I've got a VS C++ program with a section of code patched out via an #ifndef NAME.... #endif section. The NAME is defined by a /D option on the command line (which appears correctly looking on the Properties page).

Within the editor, the correct section of code is grayed out, so the editor at least is handling the #ifndef NAME correctly. However, when the application is built I get a compile error on one of the lines inside the #ifndef section -- it looks like the compiler is either ignoring the #ifndef or somehow the NAME has become un-defined. (I did do a search for NAME within the entire solution, and it is never #undef'd.)

Changing it to an #if 0 compiles as expected.

Any thoughts

Thanks


Visual C++5  
 
 
Mike Danes





PostPosted: Visual C++ Language, Compile error within code in #ifndef Top

Hmm... I tried something like this and it works fine. It would be interesting to see what kind of error you are getting and how the line from inside #ifndef section looks.


 
 
Holger Grund





PostPosted: Visual C++ Language, Compile error within code in #ifndef Top

When the #if 0 thing compiles it very much sounds like the macro is not defined at that point in the translation unit. Chances are, you're skrewed by per-file settings of the relevant .cpp file (did you select the particular .cpp file - and not the entire project - when viewing the property page ). Did you take a look at the build log (which is in my experience a better indicator of what's really going on than the command line display in the project settings)

You may also want to preprocess the file and add a couple of lines to output the definition of your macro, e.g.:

"NAME" = NAME

String literals are never expanded, so it should be easy to find in the preprocessed output.

-hg


 
 
JDC





PostPosted: Visual C++ Language, Compile error within code in #ifndef Top

Good suggestions -- I'll give it a try. How do I view the "build log"

 
 
Holger Grund





PostPosted: Visual C++ Language, Compile error within code in #ifndef Top

By default VC generates a build log oddly enough called "buildlog.htm" in your $(IntDir) or $(OutDir). I usually switch to the output window and follow the link at the bottom of the build output per Ctrl+click.

-hg