AnsweredAssumed Answered

Whitespace in nested macros with concatenation operator

Question asked by Hfuhrhurr on Aug 30, 2016
Latest reply on Sep 6, 2016 by Hfuhrhurr

Hi all,

 

I am working with VDSP 5.1.2 and stumbled across a very tiny preprocessor ugliness (as I consider it).

This code

#define CAT1(a, b) a##b

#define MACRO1(c) c##_SUFFIX

MACRO1(CAT1(A, B))

evaluates to

AB _SUFFIX

instead of

AB_SUFFIX

note the whitespace between AB and _SUFFIX in the first version.

It is, thus, impossible to concatenate with several levels of indirection.

I evaluated the same macros inside an Eclipse environment with the internal preprocessor and it worked fine.

 

Furthermore, when I put any kind of terminator at the end, like

#define CAT1(a, b) a##b;

#define MACRO1(c) c##_SUFFIX

MACRO1(CAT1(A, B))

then, the evaluation is like

AB;_SUFFIX

which, of course, doesn't help since the semicolon results in bad code.

 

I know that there will be questions like "why do you want to do things like that?".

I want to do something like this

#define MCK 01

CONNECT_OUT(PCG_CLKA_O, MCK);

and finally have a SRU macro. But this doesn't work, since there is a concatenation operator in the SRU macro which causes a whitespace in the final c code that spoils it.

Any idea what to do?

 

Best regards,

 

Rainer

Outcomes