什么标头在C ++中定义NULL?
问题描述:
根据 C ++入门,< cstdlib>
标头定义 NULL
。 cpluspplus 说,它是在< cstddef>中定义的。
。
According to C++ primer, <cstdlib>
header defines NULL
. cpluspplus says it is defined in <cstddef>
.
最终,如果不包含正确的标题,我认为 NULL
可以不会被引用。
Ultimately, if the right header is not included, I thought NULL
can't be referenced.
不过,仅包含<之后,我可以看到它,但是可以被引用并生成程序,并且可以在没有警告或错误的情况下进行编译和运行。 iostream>
请帮助我理解这一点。
答
C ++ 03第18.1.2节说NULL在cstddef中定义。
C++03 section 18.1.2 says that NULL is defined in cstddef.
在某些实现中,iostream可能包括cstddef,因此包括iostream也将包括给你NULL。
On some implementations, iostream may include cstddef, so including iostream would also give you NULL.