Search code examples
cc-preprocessorpreprocessor

Pre-processor: Expand a macro only once


Is it possible to have a macro expanded only once? In the following example, MYCONCAT is expanded to func_1(10). I want it to expand to func_BAR(10).

#define BAR 1  // included from a file I cannot change
#define FOO BAR

#define MYCONCAT2(c) func_ ## c
#define MYCONCAT(c, x) MYCONCAT2(c)(x)

MYCONCAT(FOO, 10) // is 'func_1(10)', but I want it to be 'func_BAR(10)'

Solution

  • Is it possible to have a macro expanded only once?

    No, it is not possible to partially expand a macro.