CPL.2: If you must use C, use the common subset of C and C++, and compile the C code as C++
CPL.2:如果你必须使用C,使用C和C++的共同子集,并且使用C++编译器编译C代码
That subset can be compiled with both C and C++ compilers, and when compiled as C++ is better type checked than "pure C."
这样的子集C和C++都可以编译通过,而且作为C++代码编译时获得比“纯C”更好的类型检查。
Example(示例)
int* p1 = malloc(10 * sizeof(int)); // not C++
int* p2 = static_cast<int*>(malloc(10 * sizeof(int))); // not C, C-style C++
int* p3 = new int[10]; // not C
int* p4 = (int*) malloc(10 * sizeof(int)); // both C and C++
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#cpl2-if-you-must-use-c-use-the-common-subset-of-c-and-c-and-compile-the-c-code-as-c