Stop macro expansion of bool

It's the inner FUN_H macro call that expands bool to _Bool if bool is a macro. If you lose the inner FUN_H macro and write FUN directly like so:

#include <stdio.h>
#include <stdbool.h>

#define FUN_H(TYPE) \
  void fun_##TYPE( void )

#define FUN(TYPE) \
  void fun_##TYPE( void ) { \
    printf("Type is " #TYPE ".\n"); \
  }

FUN_H(int);
FUN_H(bool);

FUN(int);
FUN(bool);

int main(void) {
  fun_int();
  fun_bool();
}

then you'll get fun_bool as expected, even if bool is a macro.


As mentioned, passing TYPE to any intermediate macro will force its expansion before further processing. So the concatenation must happen as early as possible, before passing TYPE anywhere. To achieve it without repeating ourselves too much, we can just delegate to a third macro

#define FUN_H(TYPE) \
  FUN_H_(fun_##TYPE)

#define FUN_H_(NAME) \
  void NAME( void )

#define FUN(TYPE) \
  FUN_H_(fun_##TYPE) { \
    printf("Type is " #TYPE ".\n"); \
  }