How to #define variable in C

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?

Answers


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.


Need Your Help

Way to detect the domain through PHP

php security session content-management-system

I'm using SimpleCMS to allow the client to make simple textual changes to their website; however, I'm having some issues here as part of the website is password protected through setting a PHP $_SE...

Remove source code from Static Library XCode 4

ios xcode4 static-libraries libtool-xcode

how can i remove the source code from my static library with XCode 4?

i need to make a pointer over the MapView,how to do that?

android android-layout android-manifest

Here is my location with long and lattitudes its working but i need to make pointer over there, is it possible.and also need to know can i write anything to my location on the map, plz any body hel...