CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: #warning

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    #warning

    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:-

    Code:
    #warning The warning message
    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.

    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.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: #warning

    John, did you use #warning or #pragma warning?
    The former looks like "invalid preprocessor command" (error C1021). The latter should be the correct one.
    Last edited by VictorN; July 30th, 2013 at 04:33 AM.
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: #warning

    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 . 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?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: #warning

    Well, I've just tested with
    Code:
    #warning "www"
    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:
    Code:
    fatal error C1021: invalid preprocessor command 'warning'
    Error executing cl.exe.
    PS: and yes, "The #warning Conditional Directive" is a valid directive but in Visual J++ 6.0
    Last edited by VictorN; July 30th, 2013 at 04:30 AM.
    Victor Nijegorodov

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: #warning

    Quote Originally Posted by S_M_A View Post
    note that the #warning statement is in the J++ section
    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.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: #warning

    #warning has never been valid for any version of (visual) C++

    it could be a sign the code is C# (and not C++) however.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured