如果我使用 sizeof 和 size_t 我是否应该始终包含 stddef.h
如果我在代码中使用 sizeof
运算符并使用 size_t
,我是否必须包含 stddef.h
?我没有包含 stddef.h
,并且我的代码在使用 MVS2008 和 Borland C++ BuilderX 进行编译时不会发出警告。
多谢...
if I'm using the sizeof
operator and making use of size_t
in my code, do I have necessarily have to include stddef.h
? I haven't included stddef.h
, and my code compiles without warning with both MVS2008 and with Borland C++ BuilderX.
Thanks a lot...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
sizeof()
虽然看起来像函数调用,但实际上是一个运算符,是语言核心的一部分。无需包含。size_t
在各种标头中定义:stddef.h
、string.h
、stdlib.h
和>stdio.h
。包含其中任何一个就足以在代码中使用size_t
。sizeof()
, while looking like a function call, is actually an operator and part of the language core. No include needed.size_t
is defined in various headers:stddef.h
,string.h
,stdlib.h
, andstdio.h
. Including any one of them is enough to usesize_t
in your code.不,您可以包含一个标头,该标头又包含 stddef.h
来源
No, you can include a header which in turn includes stddef.h
Source
在 c 中,
size_t
的定义来自以下几个标头之一:stddef.h
、stdio.h
、stdlib.h、
string.h
、time.h
或wchar.h
。编译器实现可以通过多种方式来实现此目的,但请注意,不能使用的一种方式是让编译器在您背后为您包含这些标头之一 - 即不允许 C 编译器执行此操作(C++ 取消了此限制,允许出于自身目的包含任何标准头文件)。
In c the definition for
size_t
comes from one of several headers:stddef.h
,stdio.h
,stdlib.h
,string.h
,time.h
orwchar.h
.There are any number of ways that the compiler implementation can arrange for this, but note that one way that can't be used is by having the compiler include one of these headers for you behind your back - that's not something a C compiler is permitted to do (this restriction was lifted for C++, which is allowed to include any of the standard headers for its own purposes).