- 包含头文件时,推荐使用c++风格
详细讨论见知乎帖子:https://www.zhihu.com/question/51288493
看下来一句话:都可以,c++风格代码风格会优雅些
#include// bad #include // good
-
非必要情况下,不使用无符号类型
主要遵循c++ google style:You should not use the unsigned integer types such as uint32_t, unless there is a valid reason such as representing a bit pattern rather than a number, or you need defined overflow modulo 2^N. In particular, do not use unsigned types to say a number will never be negative. Instead, use assertions for this.
无符号类型与有符号类型数字在一起运算时,结果未知:
下溢导致死循环
for(unsigned int i = 100; i >= 0; i--) { Print(array[i]); } -
定义enum时,使用enum class
-
定义宏函数时,使用do {}while(0);方式
-
add_definitions是全局的,会污染其他cmake文件。可以使用set_target_properties给编译目标添加编译选项
-
默认就不加SHARED了,需要链接动态库的时候可以设一个全局的BUILD_SHARED_LIBS标记
-
全局对象建议放到匿名空间使其不污染全局命名空间
-
c++代码中的struct关键字可以省略



