CPL.1: Prefer C++ to C
CPL.1:C++比C更好
C++ provides better type checking and more notational support. It provides better support for high-level programming and often generates faster code.
C++提供更好的类型检查和更多的记法支持。它为高层次编程提供更好的支持,通常也会产生更快的代码。
Example(示例)
char ch = 7;
void* pv = &ch;
int* pi = pv; // not C++
*pi = 999; // overwrite sizeof(int) bytes near &ch
The rules for implicit casting to and from void* in C are subtle and unenforced. In particular, this example violates a rule against converting to a type with stricter alignment.
C语言中有关void*的隐式类型转换的规则含糊且无用。更加严重的是,这个例子违反了防止使用直接的赋值实现类型转换的规则。
Enforcement(实施建议)
Use a C++ compiler.
使用C++编译器。
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#cpl1-prefer-c-to-c
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有