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

  • Home
  • SEARCH
  • 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 4610572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:09:00+00:00 2026-05-22T01:09:00+00:00

Just as the title says. I want to use a preprocessor macro in the

  • 0

Just as the title says. I want to use a preprocessor macro in the text of an #error statement:

#define SOME_MACRO 1

#if SOME_MACRO != 0
    #error "SOME_MACRO was not 0; it was [value of SOME_MACRO]"
#endif

In this example I want the preprocessor to resolve [value of SOME_MACRO] to the actual value of SOME_MACRO which in this case is 1. This should happen before the preprocessor, compiler or whatever processes #error prints the error output
Is there a way to do that or is this just not possible?

I don’t want to know if there is an ISO C++ standard way to do that, because afaik the preprocessor directive #error is not stated in any ISO C++ standard. However, I know GCC and Visual C++ support #error. But my question is not specific to those compilers, I’m just curious if any C/C++ compiler/preprocessor can do that.

I tried to search for that topic but without any luck.

  • 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-22T01:09:01+00:00Added an answer on May 22, 2026 at 1:09 am

    For completeness the C++0x way I suggested (using the same trick as Kirill):

    #define STRING2(x) #x
    #define STRING(x) STRING2(x)
    
    #define EXPECT(v,a) static_assert((v)==(a), "Expecting " #v "==" STRING(a) " [" #v ": "  STRING(v) "]")
    
    
    #define VALUE 1
    
    EXPECT(VALUE, 0);
    

    Gives:

    g++ -Wall -Wextra -std=c++0x test.cc                     
    test.cc:9: error: static assertion failed: "Expecting VALUE==0 [VALUE: 1]"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just as the title says, I see a lot of editors touting macro recording
Just like the title says. Because buildin widgets do not really fit, what I
Just what the title says, I need to change the password for an existing
As the title says. I want to create TooltipDialog, after I click link and
The title says everything, but just to be clear I'll add some extra words.
Like the title says, I am using devise. I want to navigate to /users/1
Just as the title says.. Is it possible to do this? Say I have
Just as in title. Is suspect it is, but I couldn't find it anywhere
I believe the title already says it all, but here is my question: what
Just looking for the first step basic solution here that keeps the honest people

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.