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

How enable digest or basic auth in IIS Express and set a user/password?

iis iis-8 http-basic-authentication digest iis-manager

I'm on Windows 2012 R2 and have IIS Express on it. How enable digest or basic auth in IIS Express and where set the username/password?

how to get all the values in table to chart values in codeigniter

php javascript codeigniter

am using the following code. am getting only the first value and it has been displaying in table. how to get all the values and display in chart. though am using for loop am getting only one value....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.