Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:28:54+00:00 2026-05-13T05:28:54+00:00

In MSVC I have this in a header: #define STR(x) #x #define STR2(x) STR(x)

  • 0

In MSVC I have this in a header:

#define STR(x)          #x
#define STR2(x)         STR(x)
#define NOTE(text)      message (__FILE__ "(" STR2(__LINE__) ") : -NOTE- " #text)
#define noteMacro(text) message (__FILE__ "(" STR2(__LINE__) ") : " STR2(text))

and I do

#pragma NOTE(my warning here)

GCC has:

#warning(my warning here)

However MSVC (2003) throws a fit when it sees #warning and gives “fatal error C1021: invalid preprocessor command ‘warning'”

What can I do about this? Is there a way to have GCC recognize MSVC warnings or MSVC not throw an error on GCC warnings? Is there something I can do that works on both? I can have GCC warn me about unknown pragmas but that’s not the most ideal solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:28:54+00:00Added an answer on May 13, 2026 at 5:28 am

    The best solution I’ve found for this problem is to have the following in a common header:

    // compiler_warning.h
    #define STRINGISE_IMPL(x) #x
    #define STRINGISE(x) STRINGISE_IMPL(x)
    
    // Use: #pragma message WARN("My message")
    #if _MSC_VER
    #   define FILE_LINE_LINK __FILE__ "(" STRINGISE(__LINE__) ") : "
    #   define WARN(exp) (FILE_LINE_LINK "WARNING: " exp)
    #else//__GNUC__ - may need other defines for different compilers
    #   define WARN(exp) ("WARNING: " exp)
    #endif
    

    Then use

    #pragma message WARN("your warning message here")
    

    throughout the code instead of #warning

    Under MSVC you’ll get a message like this:

    c:\programming\some_file.cpp(3) : WARNING: your warning message here
    

    Under gcc you’ll get:

    c:\programming\some_file.cpp:25: note: #pragma message: WARNING: your warning message here
    

    Not perfect, but a reasonable compromise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know MSVC can do this via a pragma message -> http://support.microsoft.com/kb/155196 Does gcc
I have a static library *.lib created using MSVC on windows. The size of
I am reviewing the flags we have for our MSVC projects, and I can't
i did this in msvc 2005. typedef void (*cleanup_t)(); void func(cleanup_t clean) { cleanup_t();
Under MSVC 9.0, this fails. Under g++ this compiles. If we take out the
I've never understood the need of #pragma once when #ifndef #define #endif always works.
We have many developers here using MSVC 2008 and I want to standardize the
Lets say i have two inline functions in my header file: inline int foo()
In MSVC, DebugBreak() or __debugbreak cause a debugger to break. On x86 it is
I'm tyring to convert a MSVC project from VS 2005 to VS 2008. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.