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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:54:46+00:00 2026-05-17T14:54:46+00:00

I am building an application that consists of both a windows driver written in

  • 0

I am building an application that consists of both a windows driver written in C and a user mode executable in C++. They both use a shared header file to define several macros, constants, enums, etc. In the C++ version, I want to include everything within a namespace, which a feature not supported by the C compiler. Is there certain variable I can check for to use as a preprocessor directive with Visual Studio like in the following example?

#ifdef USING_CPLUSPLUS
namespace mynamespace{
#endif

    struct mystruct{
       ...
    };


#ifdef USING_CPLUSPLUS
}
#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-17T14:54:46+00:00Added an answer on May 17, 2026 at 2:54 pm

    For the specific example of distinguishing a C++ compiler from a C compiler, the sensible choice is the macro __cplusplus which is defined by the C++ standard to exist, and due to side effects of the reserved name rules a clause that says so in standard C, will never be predefined by the C compiler.

    Every compiler has a collection of predefined macros that are occasionally useful for distinguishing among compilation hosts and target platforms. One large repository of such macros is the Predef Project where they are collecting reports on as many combinations of compiler, host, and target as they can.

    Edit: Clarifying the reserved nature of __cplusplus in C: The C standard has always reserved identifiers that begin with two underscores or one underscore followed by a capital letter. For instance, C99 in section 7.1.3 says

    “All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.”,

    and several other clauses carry a footnote that reads in part

    “Implementation-defined keywords shall have the form of an identifier reserved for any use as described in 7.1.3.”

    So, without any further direction from the standard, in a compliant implementation of a C compiler the name __cplusplus is reserved for any use. That name was chosen by the implementors of C++ specifically because it was reserved in C, has a clear meaning, and was not known to have been defined by any C implementation.

    However, by C99 the standards committee had decided to make sure that no C implementation damaged the obvious utility of a macro that could be used to distinguish a C compilation from a C++ compilation. In C99 section 6.10.8 they write:

    “The implementation shall not predefine the macro _ _cplusplus, nor shall it define it
    in any standard header.”

    Its hard to get more clear than that.

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

Sidebar

Related Questions

I'm building an application that needs to allow a user to insert text from
I am currently building an application that consists of several components, each of which
I am building php web application that let's a user upload a MS Access
I'm building an MVC application that consists of entities that can be referenced by
I've a Windows Mobile application that consists of a shell, and several modules. Each
I'm building an application that is targeting Windows, Mac and Linux soon. I was
Background: We're building an application that allows our customers to supply data in a
I'm building an application that uses an elaborate API to fetch data from Youtube,
I'm building an application that is used by several different customers. Each customer has
I'm building a application that sends a test message to another email, the program

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.