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 ...
随机推荐
- apicloud开发方法。
1.前端布局 window frame 子窗口 franmegroup 子窗口组. 一个页面比如有一个固定的顶部,然后中间区域是商品或者是什么内容,那么这个整体就是一个window,那么中间的就是i ...
- 理解Faster-RCNN 中的Anchor
先上图看一下Faster R-CNN操作流程: 图片说明:Faster R-CNN=Fast R-CNN+RPN,其中Fast R-CNN结构不变:RPN负责生成proposals,配合最后一层的f ...
- node——通过express模拟Apache实现静态资源托管
1.express中处理静态资源的函数 创建一个app.js作为入口文件,创建一个public文件夹作为静态资源文件夹 var app=express();var fn=express.static( ...
- 【BZOJ3065】带插入区间k小值
题意: 带插入,修改的区间k小值在线查询 原序列长度<=35000,插入个数<=35000,修改个数<=70000,0<=权值<=70000 题解: Orz vfleak ...
- HDU 5307 He is Flying (生成函数+FFT)
题目传送门 题目大意:给你一个长度为$n$的自然数序列$a$,定义一段区间的权值为这一段区间里所有数的和,分别输出权值为$[0,\sum a_{i}]$的区间的长度之和 想到了生成函数的话,这道题并不 ...
- Elasticsearch 入门 - 基本概念
NRT Elasticsearch 是一个 接近实时 的搜索平台.这意味着从你索引文档到其可以被搜索中间存在着一个轻微的延迟(通常为1秒钟). Cluster 一个或多个节点的完整数据.聚合索引和搜索 ...
- 【hihocoder 1032】最长回文子串
[题目链接]:http://hihocoder.com/problemset/problem/1032 [题意] [题解] 原文地址:https://segmentfault.com/a/119000 ...
- ❝ Windows系统的FTP上传下载脚本 ❞
运行环境:windows 脚本功能:从目标系统下载数据库备份文件*.dmp 执行方法:windows任务计划定时调用文件ftp.bat 文件1:ftp.bat echo 开始备份日期: >> ...
- [HTML 5] Styling with ARIA
See if you can do a better job styling this button using ARIA states. One huge benefit to styling wi ...
- An internal error occurred during: "Building workspace". java.lang.StackOverflowError
1 错误描写叙述 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW91MjNoYWk0NQ==/font/5a6L5L2T/fontsize/400/fi ...