CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    #warning and MSVC

    AFAICT it's not supported in MSVC but it seems to be much more common now for 3rd-party source code to contain #warning message lines. Is there any way they can be converted into something that'll work in MSVC but still work in the other compilers? (a #pragma maybe?) Or if not, is there some way to configure MSVC so that it'll ignore the #warning lines?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: #warning and MSVC

    In MSVS it's #pragma warning. See https://docs.microsoft.com/en-us/cpp...?view=msvc-160
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

    Re: #warning and MSVC

    Thanks 2kaud but I think that's intended for the official (i.e. numeric) warnings. OTOH #warning is generally followed by a user-defined text message
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: #warning and MSVC

    If #warning is just to display a warning message at compile time, then perhaps #pragma comment ??

    https://docs.microsoft.com/en-us/cpp...?view=msvc-160
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

    Re: #warning and MSVC

    Thanks 2kaud but if I'm reading that article correctly, #pragma comment is for inserting a comment into the compiled file.

    Over on StackOverflow someone suggested using #pragma NOTE. It doesn't actually display anything but at least it allows the compile to continue. So what'd be nice would be some magic to convert #warning statements into #pragma NOTE. But AFAICT this can't be done with #define (#define doesn't like seeing another # in the command).
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: #warning and MSVC

    How about #pragma message ?

    https://docs.microsoft.com/en-us/cpp...?view=msvc-160

    #pragma NOTE is not listed as a supported #pragma for MSVS.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

    Re: #warning and MSVC

    Wow, that looks even better - but I'd still need a way to convert #warning "whatever" into #pragma message("whatever")
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: #warning and MSVC

    How many of them are there?

    Can you use a #ifdef ... to choose between the 2 versions depending upon the compiler used? Something like:

    Code:
    #if defined (_MSC_VER)
    #pragma message("message")
    #else
    #warning "message"
    #endif
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

    Re: #warning and MSVC

    There are too many of them but I just realised that #pragma message is apparently supported by gcc - so hopefully I'll persuade the gcc programmers to use it instead of #warning
    "A problem well stated is a problem half solved.” - Charles F. Kettering

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