0-NULL-nullptr
NULL
In C
A null-pointer constant is an integral constant expression that evaluates to zero (like 0 or 0L), or the cast of such value to type void* (like (void*)0).
In C++98
A null-pointer constant is an integral constant expression that evaluates to zero (such as 0 or 0L).
In C++11
A null-pointer constant is either an integral constant expression that evaluates to zero (such as 0 or 0L), or a value of type nullptr_t (such as nullptr).
From the description of cpluscplus reference, we can see that NULL's definition is compiler dependent. In this blog, I only discuss the behavior of gcc in linux operating system.
// file test.c
#include<stdio.h>
void func(int* p) {
if (p) *p = 1;
}
int main()
{
int* p = 0;//NULL;
func(NULL);
return 0;
}
use gcc to see what's NULL is:
gcc -E test.c | less
result:
# 2 "test.c" 2
void func(int* p) {
if (p) *p = 1;
}
int main()
{
int* p = 0;
func(((void *)0));
return 0;
}
we can see that in C, NULL is (void*)0;
In C++
#include<iostream>
void func(int* p) {
if (p) *p = 1;
}
int main()
{
int* p = 0;//NULL;
func(NULL);
std::cout << p << std::endl;
return 0;
}
result:
void func(int* p) {
if (p) *p = 1;
}
int main()
{
int* p = 0;
func(__null);
std::cout << p << std::endl;
return 0;
}
it's __null, a integral constant expression.
The only change that might affect people is the type of NULL: while it is required to be a macro, the definition of that macro is not allowed to be (void*)0, which is often used in C.
For g++, NULL is #define'd to be __null, a magic keyword extension of g++.
The biggest problem of #defining NULL to be something like “0L” is that the compiler will view that as a long integer before it views it as a pointer, so overloading won't do what you expect. (This is why g++ has a magic extension, so that NULL is always a pointer.)
nullptr
typedef decltype(nullptr) nullptr_t;
Null pointer type (C++)
Type of the null pointer constant nullptr.
This type can only take one value: nullptr, which when converted to a pointer type takes the proper null pointer value.
Even though nullptr_t it is not a keyword, it identifies a distinct fundamental type: the type of nullptr. As such, it participates in overload resolution as a different type.
This type is only defined for C++ (since C++11).
0-NULL-nullptr的更多相关文章
- 语法:c++对关于空指针0/NULL/nullptr三者的演变
来源: https://blog.csdn.net/u010558281/article/details/77793644 字面意义上的解释: 0:整型常量 NULL:预处理符号 nullptr:空指 ...
- php中0," ",null和false的区别
php中很多还不懂php中0,"",null和false之间的区别,这些区别有时会影响到数据判断的正确性和安全性,给程序的测试运行造成很多麻烦.先看一个例子: <? $str ...
- 0,null,empty,空,false,isset
<?php header("Content-type: text/html; charset=utf-8"); $a=0; //1. if($a==0) { echo $a; ...
- '0','\0',NULL,EOF的区别
要看是不是一个东西,打印一下即可 printf("%d %d %d %d\n",'0','\0',NULL,EOF); 输出: 48 0 0 -1 结论: '\0'与NULL 都是 ...
- 0,null,undefined,[],{},'',false之间的关系
0与一些虚值的比较: 0与false 0==false true 0与'': =='' true 0与[]: ==[] true 0与NaN: 0==NaN false 0与undefined 0== ...
- myBatis-plus异常提示For input string: "{0=null}"
异常信息 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Per ...
- php 0,null,empty,空,false,字符串关系(转)
在php中由于是弱类型语言,不同类型值之间可以隐式转换,使得false,null,”,0,’0′这几个值的比较有些混乱,现总结一下: //相等判断 '' == NULL == 0 == false ( ...
- 0,'0','\0',NULL的区别
0,'0','\0',NULL的区别 1,0是一个值,可以是char ,int ,float,double等类型: 2,'0'是一个字符(char)类型,它的ASCII码值是48: 3,'\0'也是一 ...
- 空指针/0/NULL
空指针/0/NULL 空指针是一个被赋值为0的指针,在没有被具体初始化之前,其值为0. NULL 是一个标准规定的宏定义,用来表示空指针常量. #define NULL 0 或者 #define ...
- 你所不知道的 JS: null , undefined, NaN, true==1=="1",false==0=="",null== undefined
1 1 1 === 全相等(全部相等) == 值相等(部分相等) demo: var x=0; undefined var y=false; undefined if(x===y){ console ...
随机推荐
- 跳出语句 break continue
break 使用场景:终止switch或者循环 在选择结构switch语句中 在循环语句中 离开使用场景的存在是没有意义的 public static void main(String[] args) ...
- WPF创建自定义控件并运用
此项目源码:https://github.com/lizhiqiang0204/WpfCustomControlLibrary1 首先创建自定义控件库项目 项目名称命名为:WpfCustomContr ...
- VC++6.0进行数字图像处理的步骤以及遇到的问题
1) 2) 3) 添加CDIB类时,如果没有你要选的那个类,可以先随便选个基类继承,然后自己在代码里把基类修改成要继承的,把一些消息映射的注释掉就可以了,这样的话在建立类向导里也可以找到新建的类. / ...
- appium不能获取webview内容的解决办法
在用appium对小猿搜题app进行自动化测试时,准备用page_source打印出文章的xml内容 但是发现只能打印出外部结构内容,实际的文章内容却没有显示 截图如下 查询之后,得知需要通过cont ...
- [TJOI2018]xor
题目大意: 有一棵树,根节点为1.每个点有点权.有两种操作. 1. 求节点x所在子树中点权与y异或的最大值.2. 求x到y的路径上点权与z异或的最大值. 解题思路: 可持久化字典树. 对于第一种操作, ...
- java:递归算法
JAVA中的递归是只一个方法在(满足条件时(或不满足条件时[这里的判断根据业务的实际需求写]))自己调用自己的方法名,要求参数和方法名一致, 然后根据判断跳出该方法,返回相应的返回值! 实例: 我们要 ...
- Spring学习总结(16)——Spring AOP实现执行数据库操作前根据业务来动态切换数据源
深刻讨论为什么要读写分离? 为了服务器承载更多的用户?提升了网站的响应速度?分摊数据库服务器的压力?就是为了双机热备又不想浪费备份服务器?上面这些回答,我认为都不是错误的,但也都不是完全正确的.「读写 ...
- HDU 1475 Pushing Boxes
Pushing Boxes Time Limit: 2000ms Memory Limit: 131072KB This problem will be judged on PKU. Original ...
- 从MySQL临时表谈到filesort
内部临时表的类型和产生时机相关,翻译自:http://dev.mysql.com/doc/refman/5.6/en/internal-temporary-tables.html In some ca ...
- ie固定table单元格宽度
<table border="0" style="width:690px; table-layout:fixed;"> <tr> < ...