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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:29:33+00:00 2026-05-14T00:29:33+00:00

A preprocessor definition that includes defined(X) will never evaluate to true, but (defined X)

  • 0

A preprocessor definition that includes defined(X) will never evaluate to true, but (defined X) will. This occurs in MSVC9; I have not tested other preprocessors. A simple example:

#define FEATURE0 1
#define FEATURE1 0
#define FEATURE2 1

#define FEATURE3 (FEATURE0 && !FEATURE1 && (defined(FEATURE2)))
#define FEATURE4 (FEATURE0 && !FEATURE1 && (defined FEATURE2))
#define FEATURE5 (FEATURE0 && !FEATURE1 && (defined (FEATURE2)))

#if FEATURE3
#pragma message("FEATURE3 Enabled")
#elif (FEATURE0 && !FEATURE1 && (defined(FEATURE2)))
#pragma message("FEATURE3 Enabled (Fallback)")
#endif

#if FEATURE4
#pragma message("FEATURE4 Enabled")
#elif (FEATURE0 && !FEATURE1 && (defined FEATURE2))
#pragma message("FEATURE4 Enabled (Fallback)")
#endif

#if FEATURE5
#pragma message("FEATURE5 Enabled")
#elif (FEATURE0 && !FEATURE1 && (defined (FEATURE2)))
#pragma message("FEATURE5 Enabled (Fallback)")
#endif

The output from the compiler is:

1>FEATURE3 Enabled (Fallback)
1>FEATURE4 Enabled
1>FEATURE5 Enabled

Working cases: defined (X), defined( X ), and defined X.
Broken case: defined(X)

Why is defined evaluated differently when part of a definition, as in the #if cases in the example, compared to direct evaluation, as in the #elif cases in the example?

  • 1 1 Answer
  • 1 View
  • 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-14T00:29:34+00:00Added an answer on May 14, 2026 at 12:29 am

    defined is specific to #if and #elif. When using it through macro expansion the behavior is undefined.

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

Sidebar

Related Questions

I have the following preprocessor divective: #ifndef NDEBUG #define TRACE printf #else #define TRACE(...)
Let's say I have a source file with many preprocessor directives. Is it possible
If I write a #define that performs an operation using other preprocessor constants, is
I have a very large codebase (read: thousands of modules) that has code shared
Not sure what to make of this error. Added -D_WIN32_WINNT=0x0501 to Visual Studio's Command
The C preprocessor is justifiably feared and shunned by the C++ community. In-lined functions,
Are there any preprocessor symbols which allow something like #if CLR_AT_LEAST_3.5 // use ReaderWriterLockSlim
What would be a set of nifty preprocessor hacks (ANSI C89/ISO C90 compatible) which
Is there a way to get the C/C++ preprocessor or a template or such
I'm looking for a way to convert a preprocessor token to a string. Specifically,

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.