gpt4 book ai didi

c - NULL 被我的编译器标准库 : is it correct? 定义为 0

转载 作者:太空宇宙 更新时间:2023-11-04 00:24:09 25 4
gpt4 key购买 nike

我的 C 编译器的标准库这样定义 NULL:

#define NULL 0

我希望:

#define NULL ((void *)0)

谁能告诉我哪一个是正确的,为什么?

谢谢!

最佳答案

C 标准的最新修订版 C99 和 C11 将空量等同于零或空指针。
来自 ISO/IEC 9899:201x §6.3.2.3 指针,第 3 点:

An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.

因此,您看到的是一个完全符合 C99-C11 编译器的 NULL 声明,而不是之前的 #define NULL ((void *)0) pre C99 编译器。

关于c - NULL 被我的编译器标准库 : is it correct? 定义为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36217371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com