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 7172543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:38:10+00:00 2026-05-28T15:38:10+00:00

Parts of my code depend on the value of a preprocessor symbol: int a()

  • 0

Parts of my code depend on the value of a preprocessor symbol:

int a()
{
#if SDK_VERSION >= 3
    return 1;
#else
    return 2;
#endif
}

The comparison depends of the value of SDK_VERSION. It is expected to be a integer or something that compares to a integer, in this case, 3. If SDK_VERSION is something that cannot be compared to a integer, there will be a compile error.

Is there a way to abort the compilation if SDK_VERSION is not of an expected type? For example:

#if type(SDK_VERSION) != int  # Does not compile, I know
#error "SDK_VERSION must be an integer."
#endif
  • 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-28T15:38:11+00:00Added an answer on May 28, 2026 at 3:38 pm

    Use template to generate such error:

    template<typename T> struct macro_error;
    
    template<> struct macro_error<int> {};
    
    template<typename T> void check(T) 
    { 
       macro_error<T> SDK_VERSION_must_be_int; 
    }
    int ignored = (check(SDK_VERSION), 0);
    

    This code would generate compilation error, having the following string in it, if the SDK_VERSION is not int:

    SDK_VERSION_must_be_int
    

    See these demo:

    • http://ideone.com/mWXIm (Error : #define SDK_VERSION 1.0)
    • http://ideone.com/CRjXN (Ok : #define SDK_VERSION 1)

    And also notice the error message in the first case. It prints this:

    prog.cpp:9: error: ‘SDK_VERSION_must_be_int’ has incomplete type
    prog.cpp:9: warning: unused variable ‘SDK_VERSION_must_be_int’
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In NCover (For NUnit) it shows which parts of code are not getting hit
I would like to conditionally compile certain parts of code based on Compiler Type
anyone can explain me, why this parts of code are acting differently? while((c =
I have some parts in my code that look like this: A, B and
My company (EU-based) is considering to release some parts of our code under a
I would like to be able to skip over certain parts of my code
how to split an array index i.e.. sample code var parts = currentVal.split( );
I need to code in authentication information for specific parts of my website into
I'm going to refactor certain parts in a huge code base (18000+ Java classes).
I'd like to add parts of the source code to the XML documentation. I

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.