2

We use #warning to show compile message, like this:

#warning Are you sure it is correct?

Is is possible redefine the #warning and can choice if enable or disable it, like this:

#ifdef ACTIVE_MY_WARNING
#define #my_warning #warning
#else
#define #my_warning 
#endif

We can do it in C or not?

Rodrigo
  • 11,909
  • 23
  • 68
  • 101

2 Answers2

2

No, it's not possible to redefine preprocessor keywords (#if, #define, #ifdef, etc).

Your best shot is to have a parser that can replace your code with:

#ifdef ACTIVE_MY_WARNING
#warning Are you sure it is correct?
#endif
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • 1
    If looking for a definitive proof of this, one might cite that *"ISO/IEC 9899:TC3 6.10/1 specifies the grammar of preprocessing directives, making explicit that macro names share the exact same rules as identifiers. 6.4.2.1/1 specifies the rules for identifiers."* Thus, no `#`. http://stackoverflow.com/questions/369495/what-are-the-valid-characters-for-macro-names – HostileFork says dont trust SE Apr 26 '12 at 14:16
0

You tag it in C and as per my knowledge there is no preprocessor live #warning in c.

My question for you ans " We can do it in C or not? " is No.

Red
  • 39
  • 2