I'm compiling a module which issues a #warning statement. It's a warning that I could safely ignore. At least, I should be able to ignore it except that VC8 insists on converting it to error C1021 which is a fatal error and stops compilation. The actual line looks something like this:-
It makes no difference what the message says. I've tried several different messages but they all get converted to error C1021. It almost looks as if my compiler doesn't realise that #warning is a valid pre-processor statement. And yet, according to this MSDN entry #warning has been valid since at least VC6.
#warning The warning message
I've tried opening the project's properties and selecting different warning levels but none of the settings made any difference. Is there something I need to do to tell the compiler that #warning isn't an error condition?
At the end of the day I could just comment the line out but I'd prefer to understand why it's not working.
John, did you use #warning or #pragma warning?
The former looks like "invalid preprocessor command" (error C1021). The latter should be the correct one.
That MSDN link doesn't say anything about other VC versions and normally they do.
Also note that the #warning statement is in the J++ section :confused:. Maybe it was a mistake that it worked in VC 6 and it's "fixed" in later releases? Unfortunately I don't have VC 6 installed so I can't try it but maybe you can?
Well, I've just tested with in VC++6.0 (with SP6)
First, the "#warning" is not recognized as a valid directive: it is not colored blue, it remainf black.
Second, the error is displayed:
PS: and yes, "The #warning Conditional Directive" is a valid directive but in Visual J++ 6.0
fatal error C1021: invalid preprocessor command 'warning'
Error executing cl.exe.
You're right, I didn't notice that. Anyway, like Victor, I just fired up an old copy of VC6 and no, it doesn't work there either. So I guess that #warning is valid for Visual J++ but not for for MSVC.
Originally Posted by S_M_A
#warning has never been valid for any version of (visual) C++
it could be a sign the code is C# (and not C++) however.