-1

I am trying to define a C++ macro that contains an #ifdef. However, the preprocessor complains that it expects an expression when I use PRINT_PRETTY_FUNCTION.

#define PRINT_PRETTY_FUNCTION \
    #ifdef PRINT_FUNC_NAMES \
    printf("%s\n", __PRETTY_FUNCTION__); \
    #endif 

Does C++ allow for such a macro definition?

afp_2008
  • 1,940
  • 1
  • 19
  • 46

1 Answers1

0

#ifdef should be first in its line. It is not in your case.

These are directives to the pre-processor which only does one pass evaluating the macro (once expanded the preprocessor won't look at it again), so you just can't do what you're trying to do.

Also see this nice answer.

littleadv
  • 20,100
  • 2
  • 36
  • 50