Skip to main content
gamedev.net
🔒 Locked

Preprocessor Problems

Started by ChrisPepper1989 Sep 22, 2010 at 4:06 AM 5 replies 800+ views
Original Post
ChrisPepper1989
ChrisPepper1989
Hi everyone

Im having a strange problem with preprocessor stuff, Everywere were i seem to have something like this:

#if TEST_MODE
App->SetPlayMode(MODE_FASTTEST);

#if GRAPHICS_ENABLED
App->SetPlayMode(MODE_SLOW);
#endif

Even though TEST_MODE is defined as 1 it still skips it, and this seems to be happening with EVERY pre processer #if, #ifdef, #ifndef I have.

What could be causing this?

Thanks, Chris
Decrius
Decrius
You can do two things with preprocessor switches. You can choose between the distinction whether they're defined or not, or whether they're true or not. I usually use the former, so that when you _don't_ want a feature, you don't have to do anything with the preprocessor either.

I'm guessing that the problem is that you're mixing the above two ways. By the way, you're missing a #endif in your example; the code could look like:

#define TEST_MODE // in user space#ifdef TEST_MODE    App->SetPlayMode(MODE_FASTTEST);#else    #ifdef GRAPHICS_ENABLED        App->SetPlayMode(MODE_SLOW);    #endif#endif
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
LessBread
LessBread
Perhaps the missing #endif?

Your compiler should have a switch that outputs the preprocessed translation unit. Find that switch, direct the output to a file for easier examination, examine.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
ChrisPepper1989
ChrisPepper1989
Sorry everyone i should have been more specific!

The code was actually:

#if TEST_MODE
App->SetPlayMode(MODE_FASTTEST);

#if GRAPHICS_ENABLED
App->SetPlayMode(MODE_SLOW);
#endif
#endif

I just missed the last endif in the c&p! sorry!

My compiler is Visual Studios 2005 Professional and im also using the plug in Visual Assist.

The language is C++ but there is also alot of C type code mixed in aswell

@Decrius, I am mixing a little i shall try just using #if, I also prefer #ifdef but its a work project and the common practice is #if.

Zahlman
Zahlman
Quote:
Original post by ChrisPepper1989
Even though TEST_MODE is defined as 1


How do you know this is actually the case?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.