在 Python 源代码中使用__cplusplus

use of __cplusplus in python source

本文关键字:cplusplus Python 源代码      更新时间:2023-10-16

在python源代码中的头文件中跟随有什么用

#ifdef __cplusplus
extern "C" {
#endif

这是否意味着 Python 为我们提供了使用编译器构建代码C++?如果是,那么使用 C 构建 Python 源代码和C++编译器之间有什么区别吗

Python API仍然是纯C。这些指令只允许在C++代码中包含标头。

__cplusplus宏是使用 C++ 编译器编译代码时隐式定义的。因此,只有当看到extern "C"规范的编译器支持它时,才会添加它。