Preprocessor #warning Command Question

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Preprocessor #warning Command Question

 
0
  #1
Oct 7th, 2008
Is there a way to #define something as a #warning?
I tried using the following code, but it gives me an error:
'warning' undeclared (first use this function)

This is the part of code where the error appears:
  1. #define something #warning This is not a standard function!
  2.  
  3. int main(void)
  4. {
  5. something
  6. return 0;
  7. }


Any help on this please?
If it's not possible to perform, please tell

Thanks in advance
Last edited by unbeatable0; Oct 7th, 2008 at 10:45 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: Preprocessor #warning Command Question

 
0
  #2
Oct 7th, 2008
Never mind, I found the answer
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: Preprocessor #warning Command Question

 
0
  #3
Oct 7th, 2008
Oh well... I was wrong. My method didn't work
Please help me
Reply With Quote Quick reply to this message  
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
  #4
Oct 7th, 2008
I don't think the pre-processor is capable of expanding lines which are themselves pre-processing statements.

In short, I don't think it's going to work.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: Preprocessor #warning Command Question

 
0
  #5
Oct 8th, 2008
Any help on this? If it helps, I want the macro to be a function. For example:

  1. #ifndef _WINDOWS_H
  2. #define test(); #warning <windows.h> needs to be included for this function!
  3. #endif
  4. int main(void)
  5. {
  6. test();
  7. return 0;
  8. }

If it's not possible to do this way, is there another way to do it, which will give a warning instead of the function, in case the function cannot be used?
Last edited by unbeatable0; Oct 8th, 2008 at 4:46 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Preprocessor #warning Command Question

 
0
  #6
Oct 8th, 2008
Salem is right; there is no way to #define a macro that expands to a preprocessor directive.

There is also the incidental concern that #warning is not a standard preprocessor directive.

Any C++ compiler will generate an error on an attempt to call a function that has not previously been declared.

I can't see the point of what you're trying to do. If <window.h> is not included
  1. #ifndef _WINDOWS_H
  2. #error <windows.h> needs to be included to compile this source file
  3. #endif
will generate an error message that gives specific information on requirements.

Of course, if you need to use the above (eg if you have a header that relies on <windows.h>) it would be easier to #include <windows.h> anyway
Reply With Quote Quick reply to this message  
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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC