0

I have a file called config.h with the following...

#define GL_DOOM

Then I have the following in another file m_misc.c...

#include "config.h"
...
#if ((defined GL_DOOM) && (defined _MSC_VER))
LOGD("Using glboom-plus.cfg");
#define BOOM_CFG "glboom-plus.cfg"
#else
LOGD("Using prboom-plus.cfg");
#define BOOM_CFG "prboom-plus.cfg"
#endif

But it says...

05-02 14:40:24.789: D/Doom(2966): Using prboom-plus.cfg

What is the deal here? I am new to C so what am I missing?

6
  • 6
    && (defined _MSC_VER) <- _MSC_VER seems to not be defined. Commented May 2, 2013 at 14:47
  • 1
    which compiler are you using? Commented May 2, 2013 at 14:48
  • Is the line #define GL_DOOM in config.h getting parsed? For example, are there #if's or #ifdef's around it? Commented May 2, 2013 at 14:49
  • @DanielFischer seems the right answer why you did not put it as an answer ? Commented May 2, 2013 at 14:49
  • As for compiler I am using the gcc compiler on Android NDK (So bionic) Commented May 2, 2013 at 15:24

3 Answers 3

4

Let's take the following code:

#define GL_DOOM
#define _MSC_VER

#if ((defined GL_DOOM) && (defined _MSC_VER))
LOGD("Using glboom-plus.cfg");
#else
LOGD("Using prboom-plus.cfg");
#endif

I can compile that code with g++ -E which will output the result of the preprocessor. Let's look at that output.

# 1 "blah.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "blah.c"

LOGD("Using glboom-plus.cfg");

So, to me, this implies that you probably don't have both GL_DOOM and _MSC_VER defined.


You might verify this with a test that looks something like:

#include "config.h"

#ifndef GL_DOOM
#error GL_DOOM is not defined
#endif

#ifndef _MSC_VER
#error _MSC_VER is not defined
#endif

It's also worth noting something. _MSC_VER is a preprocessor symbol that is defined almost strictly by Microsoft Visual Studio. If you're not compiling with that software, then the expectation would be that it would not be defined.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for educating on -E and #error to debug preprocessing step.
2
#include "config.h"

that includes the #define GL_DOOM.

...
#if ((defined GL_DOOM) && (defined _MSC_VER))

That checks whether both, GL_DOOM and _MSC_VER are defined.

Since GL_DOOM is defined, either your preprocessor is totally broken, or _MSC_VER is not defined.

Comments

0

The check

#if ((defined GL_DOOM) && (defined _MSC_VER)) 

will only evaluate to true if both the conditions are met. You have not specified whether you have defined _MSC_VER in the header file. That is probably the reason why it is executing the else condition.

If you want to log when either of those are defined in the header file, use the OR operation instead:

#if (defined (GL_DOOM)) || (defined (_MSC_VER))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.