0

Possible Duplicate:
Macro for concatenating two strings in C

I have a function that looks something like this:

bool module_foo_process(void* bar) { return doMagic(bar); }

Now, I'd like to generate it with a macro. For instance, the macro for the above function would look like this:

MY_AMAZING_MACRO(foo)

This allows me to write something like:

MY_AMAZING_MACRO(awesome)

and get this:

bool module_awesome_process(void* bar) { return doMagic(bar); }

Any ideas on how this can be accomplished in C?

Community
  • 1
  • 1
Brett
  • 4,066
  • 8
  • 36
  • 50

2 Answers2

5
#define MY_AMAZING_MACRO(name) \
  bool module_##name##_process(void* bar) { return doMagic(bar); }
Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132
4

Use the concatenation operator ##:

#define MY_AMAZING_MACRO(foo) bool module_##foo##_process(void* bar) { return doMagic(bar); }

See the gcc online documentation for more details: Concatenation.

DrummerB
  • 39,814
  • 12
  • 105
  • 142