1

What is the use of following in the header files in python source

#ifdef __cplusplus
extern "C" {
#endif

Does it means Python provides us to build code using C++ compiler. If yes, then are there any differences between building the python source using C and C++ compiler

2
  • This means you can build Python itself with a C/C++ compiler. Commented Jan 24, 2017 at 8:28
  • 1
    I cannot imagine any advantage in using a C++ compiler (for base python) instead of C. One reason for these might be to allow extension modules written in C++ to use them. See also boost.org/doc/libs/1_39_0/libs/python/doc/index.html Commented Jan 24, 2017 at 9:25

1 Answer 1

5

The Python API is still pure C. These directives simply allow for the inclusion of the header in C++ code.

The __cplusplus macro is defined implicitly when compiling code with a C++ compiler. So this way the extern "C" specification is added only when the compiler that sees it will support it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.