0

I have a macro definition:

#define MY_PREFIX prefix_

Then I want to have definitions with concatenated suffices. I tried the following:

#define MY_NAME1 MY_PREFIXsuffix // Evaluates to 'MY_PREFIXsuffix'
#define MY_NAME2 MY_PREFIX ## suffix // Evaluates to 'MY_PREFIXsuffix'
#define MY_VAL(val) val // Intermediate macro
#define MY_NAME3 MY_VAL(MY_PREFIX)suffix // Evaluates to 'prefix_ suffix'
#define MY_NAME4 MY_VAL(MY_PREFIX) ## suffix // Evaluates to 'prefix_ suffix, preprocessor complains
#define CONCAT(a, b) a ## b 
#define MY_NAME5 CONCAT(MY_PREFIX, suffix) // Evaluates 'MY_PREFIXsuffix'

I thought that this should be simple. Any ideas?

The desired output should be that MY_NAME evaluates to 'prefix_suffix' (without the quotes)

Kostas
  • 1,292
  • 1
  • 13
  • 20
  • Thanks for the answer. I tried it and it evaluates to 'MY_PREFIXsuffix'. I also updated the question with your suggestion. – Kostas Feb 22 '17 at 16:28
  • sorry, I was looking for a dupe, and I left out the extra level of indirection which is needed. See the answer to the linked duplicate for an explanation.. `#define CONCAT_(a,b) a##b` `#define CONCAT(a,b) CONCAT_(a,b)` `#define MY_NAME CONCAT(MY_PREFIX, suffix` – rici Feb 22 '17 at 16:33
  • Last suggestion worked indeed. Thanks. – Kostas Feb 22 '17 at 16:36

0 Answers0