How to #define variable in C
I have a file called config.h with the following...
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?
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.