use of __cplusplus in python source

At the top of each C header file (after the include guards), use this
1
2
3
#ifdef __cplusplus
extern "C" {
#endif 


and at the bottom, need to enclose

1
2
3
#ifdef __cplusplus
}
#endif 

This if loop tutorial will help: https://www.theengineeringprojects.com/2019/11/how-to-use-if-loop-in-c.html
Last edited on
It means that the extern symbols are in C format and not C++ format. ie the names are not mangled to include their type. This also means that overloaded functions can't be used. This means that the function parameters can only use C types (no std::string etc). This way the same library can be used by both C and C++ programs.

See https://en.cppreference.com/w/cpp/language/language_linkage
What is the use of following in the header files in python source
I don't think that this appears in phyton code.

Does it means Python provides us to build code using C++ compiler.
Python is a language. Compiler is something different. It migth be possible to build a toolchain that compiles both.

However you can combine the two languages. See:

https://docs.python.org/3/extending/extending.html#

For python compilers see:

https://hackr.io/blog/best-python-compilers
CPython (by far, the most widely used implementation of Python) is written in C (and Python).

Source code: https://github.com/python/cpython
There is no C++ in the Python source.

github reports:
Languages
Python 62.6%
C 35.3%
C++ 0.7%
...

https://github.com/python/cpython
The dirty sh!t dale14886 edited their post with spam.
Topic archived. No new replies allowed.