Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compare #ifdef values for conditional use

I'm trying to come up with a generic, easy to use way to only run certain code, depending upon the api I am using at the time.

In a header:

#define __API_USED cocos2d-x

#define COCOS2DX  cocos2d-x
#define OPENGL opengl

#ifdef __API_USED == COCOS2DX
    #define USING_COCOS2DX
    #undef USING_OPENGL
#endif

in source:

#ifdef USING_COCOS2DX
    ......
#endif

However I don't think this would work.

Is there a way to accomplish what I am looking to do?

like image 320
Jasmine Avatar asked Aug 11 '14 23:08

Jasmine


1 Answers

You can but you need to do it like this:

#define __API_USED COCOS2DX

#define COCOS2DX  1
#define OPENGL 2

#if __API_USED == COCOS2DX
    #define USING_COCOS2DX
    #undef USING_OPENGL
#endif

As Keith Thompson explained undefined tokens (macros) like cocos2d and x evaluate to 0 so you need to define values for the macros you're using.

like image 133
Ross Ridge Avatar answered Oct 03 '22 04:10

Ross Ridge