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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:58:11+00:00 2026-06-15T15:58:11+00:00

I have a question about Preprocessor directives in C and C++. I have the

  • 0

I have a question about Preprocessor directives in C and C++.

I have the following code:

#ifdef __cplusplus
//part A
extern "C" 
{
// somecode here
}
#else
//part B
#endif

I know the c++ complier predefined the __cplusplus will c compiler does not.

And I put this set of code into a c header file, and c++ file will include this c header file. And my question is: if the file is compiled by a c++ compiler, it will compile the part A, and if it is compiled by a c compiler, it will compile the part B, but normally, we use this code to make c++ file and c file interact with each other, if we have such code above, I mean we have both C and C++ file together, and we use gcc compiler, how this code is compiled? only part A is compiled? or only part B is compiled? or the code is devided into two parts, part A is compiled for C++ and part B is compiled for C file at the same time?

  • 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-06-15T15:58:13+00:00Added an answer on June 15, 2026 at 3:58 pm

    In a project with multiple source files, the header is not processed just once by the compiler.

    When the compiler compiles a C++ file, it reads that file and any headers it includes (directly or indirectly) and processes the contents of those files using the rules for C++.

    When the compiler compiles a C file, it reads that file and any headers it includes (directly or indirectly) and processes the contents of those files using the rules for C.

    The result will be as if the code in your header file appeared separately in the C++ source and in the C source.

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

Sidebar

Related Questions

I have a question about how GC works in Java. Consider the following code:
I have question about throw. How will the throw work in the following code?
I have a question about arithmetic behaviour in R. Regard the following piece of
I have question about Dictionaries in Python. here it is: I have a dict
I have question about try, catch and finally in Java. Consider the following scenario:
https://stackoverflow.com/a/64983/468251 - Hello, I have question about this code, how made that working with
I have question about JUnit tests. I am trying to test my code and
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all

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.