Reputation: 1547
In C I wanted to use preprocessor directives inside a macro. Since this doesn't work, I stumbled over this answer about variadic macros, where a macro accepts a varying amount of arguments.
The answer contained following example:
#ifdef FOO
#define IF_FOO(...) __VA_ARGS__
#define NO_FOO(...)
#else
#define IF_FOO(...)
#define NO_FOO(...) __VA_ARGS__
#endif
IF_FOO(
#define BAR 5
int foo = BAR;
)
NO_FOO(
#define foo 5
)
As you can see, there's a #define
inside IF_FOO
, which compiles without errors. However when I use #include
it still compiles but the is underlined red (see below). I use the following code:
#ifdef HW_TEST
#define IF_HW_TEST(...) __VA_ARGS__
#else
#define IF_HW_TEST(...) /* ignore */
#endif
IF_HW_TEST(
#include "hwTesting.h"
TestMain();
return;
)
What's the reason for this, or am I missing something?
I use Eclipse (Renesas e2 Studio) and the CC-RL compiler.
Upvotes: 1
Views: 60