定义NULL和NULL_POINTER的正确方法? [英] Correct way of defining NULL and NULL_POINTER?

查看:139
本文介绍了定义NULL和NULL_POINTER的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知, C 定义NULL是这样的:

As far as I know, C defines NULL like this:

#define NULL ( (void *) 0)

然后,我们应该如何定义NULL_POINTER?我在程序中定义了相同的代码,并且可以正常工作,但我想那只是一个巧合:

Then, how should we define NULL_POINTER ? I defined it the same in my program and it worked, but I suppose that is just a coincidence:

#define NULL_POINTER ( (void *) 0)

如果有的话,逻辑定义是什么?

What would be the logical definition, if any ?

推荐答案

#define NULL ( (void *) 0)

#define NULL 0

都有效.如果您需要为空指针实现自己的宏,则适用相同的规则.

are both valid. If you need to implement your own macro for null pointer, the same rule applies.

C11(ISO/IEC 9899:201x)§6.3.2.3指针第3节

具有值0的整数常量表达式,或此类强制转换为类型的表达式 void *,称为空指针常量

C11(ISO/IEC 9899:201x) §6.3.2.3 Pointers Section 3

An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant

这篇关于定义NULL和NULL_POINTER的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆