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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:19:47+00:00 2026-05-31T03:19:47+00:00

For compiler-specific code, it’s common to see cpp directives such as: #if defined (__GNUC__)

  • 0

For compiler-specific code, it’s common to see cpp directives such as:

#if defined (__GNUC__) && (__GNUC__ >= 4)

which is the preprocessor test I typically use – not exclusively for __GNUC__, but it’s a common example. Alternatively,

#if (__GNUC__ >= 4)

appears to satisfy the same requirements. Are there potential problems with the latter? Not only with gcc, but any standards-conforming preprocessor. Can the LHS be evaluated as a certain value, even if it’s not defined? Are there any pitfalls to the second approach that any language lawyers are aware of?

  • 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-31T03:19:48+00:00Added an answer on May 31, 2026 at 3:19 am

    The preprocessor assumes undefined macros to have the value 0 in comparisons, so your simplification is ok in this case. If you want to check against a lower version than 4 in gcc, you may get into trouble though since it would evaluate as true with a < even if it’s not gcc.

    I think the reason for using both is also a question of understandability, if you check

    #if defined(__GNUC__) && (__GNUC>=4)
    

    it’s rather obvious you’re not already in a block with code that only is for GCC, while the simplification

    #if (__GNUC__ >= 4)
    

    does not make that obvious and can be read as a version check only when you already know it’s gcc.

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

Sidebar

Related Questions

In Delphi, you can use compiler directives to disable specific warnings, such as {$WARN
Is there such macro in C++ (cross-compiler or compiler-specific): #if isclass(NameSpace::MyClass) Would be useful.
So I can do something like #ifdef MSVC //do compiler specific code here #endif
I realize that far is compiler specific, but my expectation is that the placement
Can any Flash compiler put specific scripts on specific frames of the Flash movie
Is there a specific Xcode compiler flag that gets set when compiling for iPad?
This might be iPhone specific, I'm not sure. The compiler doesn't complain when building
I have some sample code from Tuaw which is probably 3 releases old ;)
To my understanding the representation of size_t and wchar_t are completely platform/compiler specific. For
In C++/CLI code I need to check if the type is a specific generic

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.