On 25.04.2016 12:24, Christof Warlich wrote:
>
> I'm unhappy with these two lines from this example code:
>
> #define HELLO
> PRINT(#define HELLO);
>
But what about it are you unhappy with?
Possibly you're reacting to the nonsense: the “#define” directive is not
necessary and has no effect on the PRINT.
Possibly you're reacting to the use of the preprocessor.
Possibly it strikes you as odd that something with a space in it can be
a single macro argument, but the preprocessor is a different language.
Possibly you're an experienced programmer who reacts to the formal
Undefined Behavior, “if there are sequences of preprocessing tokens
within the list of arguments that would otherwise act as preprocessing
directives, the behavior is undefined” (under the reasonable assumption
that the /intent/ was to make even a single directive-like sequence UB).
Possibly you don't like the use of simple macro names like PRINT, which
can easily collide, and would prefer e.g. MYCOMPANY_THEAPP_PRINT.
But it's practically impossible for us to narrow it down: /we are not
telepaths/.
> Is there any way to write a macro that expands to these two lines,
> expecting "#define HELLO" as parameter?
Certainly. Just do it.
> Thanks for any help. Even suggestions involving compiler specific
> extensions would be appreciated.
None needed.
But note that you can't have a generated “#define” evaluated by the
preprocessor.
Hence the generated text will be invalid as C++ code.
Cheers & hth.,
- Alf