Daniel said:
Is there a preprocessor directive that will cause the compiler to print
a warning diagnostic of whatever message that I choose?
...
As others pointed out, only "#error" is available, and it will stop
the compilation.
If you can tolerate a misleading warning, the following macro is a
"shoot from the hip", non-portable, very poor attempt to show a
warning by creating something else the compiler should warn you about.
Caveats:
(a) Can be used only inside functions.
(b) The warning text must be a valid C identifier
(almost, it may begin with a digit):
WARNING(about_something) is OK,
WARNING(something happened!!) is not.
(c) Since it creates a block, it may alter flow control:
if (condition)
WARNING(xxx)
process(condition)
is not what it looks.
(d) Probably other things I did not think of.
Outside functions, a similar macro could create a prototype for a
static function with the text embedded in the function name.
With the right parameters gcc will warn of a function declared static
but never defined.
--------------------
$ cat wtest.c
/* use inside functions only, be aware of side effects */
#define WARNING(x) { static char WARNING_ ## x; }
int main(void)
{
#if ODD
WARNING(odd)
#else
WARNING(even)
#endif
return 0;
}
$
$ gcc -ansi -Wall -DODD=1 wtest.c
wtest.c: In function 'main'
wtest.c:8: warning: unused variable 'WARNING_odd'
$
$ gcc -ansi -Wall -DODD=0 wtest.c
wtest.c: In function 'main'
wtest.c:10: warning: unused variable 'WARNING_even'
$
Roberto Waltman
[ Please reply to the group,
return address is invalid ]