View Single Post
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Preprocessor #warning Command Question

 
0
  #7
Oct 8th, 2008
> #define test(); #warning <windows.h> needs to be included for this function!
But if you don't have windows.h, then the code would have failed to compile before this point anyway.

How to tell your OS/Compiler/etc at compile-time
http://predef.sourceforge.net/

You have to do something like this
  1. #ifdef _WIN32
  2. #include <windows.h>
  3. #else
  4. #warning needs windows.h
  5. // in case the compiler ignores #warning
  6. int test ( ) {
  7. fprintf( stderr, "_WIN32 not set, compilation should have failed!\n" );
  8. exit( 0 );
  9. return 0;
  10. }
  11. #endif

Or if you're trying to spot obsolete functionality, and you're using gcc, then perhaps this (this is the 2nd obscure snippet from the gcc manual today )
Originally Posted by gcc manual
deprecated
The deprecated attribute results in a warning if the variable is used anywhere
in the source file. This is useful when identifying variables that are expected
to be removed in a future version of a program. The warning also includes the
location of the declaration of the deprecated variable, to enable users to easily
find further information about why the variable is deprecated, or what they
should do instead. Note that the warning only occurs for uses:
extern int old_var __attribute__ ((deprecated));
extern int old_var;
int new_fn () { return old_var; }
results in a warning on line 3 but not line 2.
Reply With Quote