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的更多相关文章

  1. 语法:c++对关于空指针0/NULL/nullptr三者的演变

    来源: https://blog.csdn.net/u010558281/article/details/77793644 字面意义上的解释: 0:整型常量 NULL:预处理符号 nullptr:空指 ...

  2. php中0," ",null和false的区别

    php中很多还不懂php中0,"",null和false之间的区别,这些区别有时会影响到数据判断的正确性和安全性,给程序的测试运行造成很多麻烦.先看一个例子: <? $str ...

  3. 0,null,empty,空,false,isset

    <?php header("Content-type: text/html; charset=utf-8"); $a=0; //1. if($a==0) { echo $a; ...

  4. '0','\0',NULL,EOF的区别

    要看是不是一个东西,打印一下即可 printf("%d %d %d %d\n",'0','\0',NULL,EOF); 输出: 48 0 0 -1 结论: '\0'与NULL 都是 ...

  5. 0,null,undefined,[],{},'',false之间的关系

    0与一些虚值的比较: 0与false 0==false true 0与'': =='' true 0与[]: ==[] true 0与NaN: 0==NaN false 0与undefined 0== ...

  6. myBatis-plus异常提示For input string: "{0=null}"

    异常信息 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Per ...

  7. php 0,null,empty,空,false,字符串关系(转)

    在php中由于是弱类型语言,不同类型值之间可以隐式转换,使得false,null,”,0,’0′这几个值的比较有些混乱,现总结一下: //相等判断 '' == NULL == 0 == false ( ...

  8. 0,'0','\0',NULL的区别

    0,'0','\0',NULL的区别 1,0是一个值,可以是char ,int ,float,double等类型: 2,'0'是一个字符(char)类型,它的ASCII码值是48: 3,'\0'也是一 ...

  9. 空指针/0/NULL

    空指针/0/NULL 空指针是一个被赋值为0的指针,在没有被具体初始化之前,其值为0. NULL 是一个标准规定的宏定义,用来表示空指针常量. #define NULL 0   或者 #define ...

  10. 你所不知道的 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 ...

随机推荐

  1. 是时候学习 RxSwift 了

    相信在过去的一段时间里,对 RxSwift 多少有过接触或耳闻,或者已经积累了不少实战经验.此文主要针对那些在门口徘徊,想进又拍踩坑的同学. 为什么要学习 RxSwift 当决定做一件事情时,至少要知 ...

  2. JS 猴子

    公园里有一只猴子和一堆桃子,猴子每天吃掉桃子总数的一半,把剩下一半中扔掉一个坏的. 到第七天的时候,猴子睁开眼发现只剩下一个桃子.问公园里刚开始有多少个桃子? <!DOCTYPE html> ...

  3. 路飞学城Python-Day107

    88-Ajax简介 Ajax是前端的JS技术,目前向服务器发送请求是通过1.向浏览器的地址栏发送请求的方式:2.form表单的请求方式是两种get和post方式:3.a标签的href属性对接地址 是一 ...

  4. 获取淘宝sessionkey 实时保存

    <?php/* * To change this license header, choose License Headers in Project Properties. * To chang ...

  5. 实验二:1、输出“Hello Word!”;2、测试主方法 的输入参数。3、总结

    一.输出:“Hello Word!” 1.新建java项目:点击File->New->Java Project.在project name一栏中输入自己所要创建的项目名称,点击Finish ...

  6. Django 连接MySQL 通过pymysql 库

    ython3 如何安装pymysql 库,在此不再做多的讲解,如果有想知道如何安装的朋友,请求参考下面的连接地址: 第一步:应用setting.py 文件设置mysql 数据库连接相关属性.   DA ...

  7. XSS Chanllenges 11-15

    Stage #11 根据提示,发现正则匹配,过滤掉了很多关键字 除on 事件和script 事件外,能执行js 代码的还有a 标签构造的超链接 构造 "><a href=java ...

  8. Project Euler 14 Longest Collatz sequence

    题意:对于任意一个数 N ,寻找在 100,0000 之内按照规则( N 为奇数 N = N * 3 + 1 ,N 为偶数 N = N / 2 ,直到 N = 1 时的步数 )步数的最大值 思路:记忆 ...

  9. selenium+java处理鼠标悬停

    1.元素比较明确(可视) 2.元素隐藏,需要鼠标移动到一定地方才显现(下图为某论坛列表,需要将鼠标移动到列表才显示操作按钮)

  10. HTTP中的重定向和请求转发的区别(转)

    时间长有些忘了,转篇文章加深一下印象: 一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下:request.getRequestDispatcher("new.jsp&qu ...