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

查看:22
本文介绍了定义 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.

值为 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天全站免登陆