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
  • 3,926
  • 7
  • 32
  • 48

2 Answers2

5
#define MY_AMAZING_MACRO(name) \
  bool module_##name##_process(void* bar) { return doMagic(bar); }
Vaughn Cato
  • 61,903
  • 5
  • 80
  • 122
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,275
  • 12
  • 103
  • 141