google c++ style与qt Coding Rules关于Null Pointers的分歧
时间:2011-12-23
来源:互联网
0 and NULL
link ▽
Use 0 for integers, 0.0 for reals, NULL for pointers, and '\0' for chars.
Use 0 for integers and 0.0 for reals. This is not controversial.
For pointers (address values), there is a choice between 0 and NULL. Bjarne Stroustrup prefers an unadorned 0. We prefer NULL because it looks like a pointer. In fact, some C++ compilers, such as gcc 4.1.0, provide special definitions of NULL which enable them to give useful warnings, particularly in situations where sizeof(NULL) is not equal to sizeof(0).
Use '\0' for chars. This is the correct type and also makes code more readable.
Qt Creator Coding Rules
Null Pointers
Using a plain zero (0) for null pointer constants is always correct and least effort to type.
void *p = 0;
-NOT-
void *p = NULL;
-NOT-
void *p = '\0';
-NOT-
void *p = 42 - 7 * 6;
Note: As an exception, imported third party code as well as code interfacing the native APIs (src/support/os_*) can use NULL.
很多项目代码中指针直接用 p = 0; 来赋值 用if (p) 来判断
我个人一直用 p = NULL; if (p == NULL) 这种形式
分歧有没有,纠结有没有
作者: zmlovelx 发布时间: 2011-12-23
作者: sryan 发布时间: 2011-12-23
作者: akirya 发布时间: 2011-12-23
作者: dahuaixiaohuai 发布时间: 2011-12-23
作者: qq120848369 发布时间: 2011-12-23
作者: wodeprogrammer 发布时间: 2011-12-23
作者: yisikaipu 发布时间: 2011-12-23
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28