Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define and how to use them - C++

In a pre-compiled header if I do:

#define DS_BUILD
#define PGE_BUILD
#define DEMO

then in source I do:

#if (DS_BUILD && DEMO)
    ---- code---
#elif (PGE_BUILD && DEMO)
    --- code---
#else
    --- code ---
#endif

Do I get an error that states:

error: operator '&&' has no right operand

I have never seen this before. I am using XCode 3.2, GCC 4.2 on OS X 10.6.3

like image 831
MLS Avatar asked Nov 30 '22 10:11

MLS


1 Answers

You need to add the defined keyword since you want to check that you defined have been defined.

#if defined (DS_BUILD) && defined (DEMO)
    ---- code---
#elif defined (PGE_BUILD) && defined (DEMO)
    --- code---
#else
    --- code ---
#endif
like image 120
shf301 Avatar answered Dec 05 '22 05:12

shf301