I just saw this thread, describing how to add conditional macros: Conditional value for a #define
but in my case I am defining a function within the condition.
#if TARGET_IPHONE_SIMULATOR
#define doSomething(){\
\\ does something
}\
#else
#define doSomething(){\
\\ does something else
}\
#endif
This does work, except I is causing gcc compiler to throw this warning:
"doSomething" redefined
This is the location of the previous arguments
Is there any workaround to help getting rid of the warnings?
UPDATE:
So I tried including the condition inside my definition:
#define doSomething(){\
#if TARGET_IPHONE_SIMULATOR
\\ do something
#else
\\ do something else
#endif
}\
but that throws an error:
error: '#' is not followed by a macro parameter.
I found the answer to my question here.
Conclusion: you cannot include #ifdef etc... inside #define, because there should only be one pre-processing directive per line.
So although we can break the line with a backslash '\' this helps writing readable multiline macros, but the preprocessor will see it as one line:
#define doSomething(){ #if TARGET_IPHONE_SIMULATOR ... #endif }
Which throws this error:
error: '#' is not followed by a macro parameter.
That makes sense, so I will have to rethink my implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With