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 ...
随机推荐
- mach-o格式分析
0x00 摘要 人生无根蒂,飘如陌上尘. 分散逐风转,此已非常身. — 陶渊明 <杂诗> mach-o格式是OS X系统上的可执行文件格式,类似于windows的PE与linux的ELF, ...
- LSTM比较RNN
LSTM只能避免RNN的梯度消失(gradient vanishing),但是不能对抗梯度爆炸问题(Exploding Gradient). 梯度膨胀(gradient explosion)不是个严重 ...
- TensorFlow+实战Google深度学习框架学习笔记(11)-----Mnist识别【采用滑动平均,双层神经网络】
模型:双层神经网络 [一层隐藏层.一层输出层]隐藏层输出用relu函数,输出层输出用softmax函数 过程: 设置参数 滑动平均的辅助函数 训练函数 x,y的占位,w1,b1,w2,b2的初始化 前 ...
- Project Euler 44 Sub-string divisibility( 二分 )
题意:五边形数由公式Pn=n(3n−1)/2生成,在所有和差均为五边形数的五边形数对Pj和Pk中,找出使D = |Pk − Pj|最小的一对:此时D的值是多少? 思路:二分找和差 /********* ...
- POJ3984-迷宫问题【BFS】
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...
- [bzoj3743 Coci2015] Kamp(树形dp)
传送门 Description 一颗树n个点,n-1条边,经过每条边都要花费一定的时间,任意两个点都是联通的. 有K个人(分布在K个不同的点)要集中到一个点举行聚会. 聚会结束后需要一辆车从举行聚会的 ...
- MAVEN 的常用命令
1.清除命令:mvn clean 2.编译命令:mvn conpile 3.打包命令:mvn package 4.跳过单元测试命令:mvn clean package -Dmaven.test.sk ...
- hibernate在maven中自动生成
1.构建数据库连接 2.新建maven项目,利用工具生成hibernate相应的类和xml文件 新建pojo包 右击项目 点击Configure Facets 选择hibernate 选择包 选择驱动 ...
- 使用fatjar来实现将包括第三方jar包的项目到处成一个jar包供其它程序使用
一.在线安装fat jar 在线安装步骤: eclipse菜单条 help >software updates >Search for new features to install> ...
- Tom和Jerry来了,Tom和Jerry走了——北漂18年(38)
上次讲到跟我同一时候入职的女销售走了. 回忆起来,她的问题多半是技巧足够,脑子不足够,走了之后再没联系.不久之后,在老板的要求之下.LilyG又招聘了两位男销售,英文名字非常登对一个叫Tom,一个叫J ...