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...
h is a header file in the standard library of the C programming language that defines the macros NULL and offsetof as well as the types ptrdiff_t, wchar_t, and size_t.
The sizeof operator yields the size in bytes of the operand, which can be an expression or the parenthesized name of a type. The result for either kind of operand is not an lvalue, but a constant integer value. The type of the result is the unsigned integral type size_t defined in the header file stddef. h .
In c the definition for size_t comes from one of several headers: stddef. h , stdio. h , stdlib. h , string.
No; size_t is not necessarily whatever you mean by 'the word size' of the machine that will run the code (in the case of cross-compilation) or that compiled the code (in the normal case where the code will run on the same type of machine that compiled the code).
No, you can include a header which in turn includes stddef.h
The size_t definition shall be provided to a referencing piece of code by including stdlib.h header file. In fact most implementations don't have it defined literally in this file but instead do sub include the file stddef.h as for example the standard library of the GNU C compiler does. The direct inclusion of stddef.h for application code is totally valid and thus can replace stdlib.h in cases where no other members from this file are needed or desired.
Source
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
, and stdio.h
. Including any one of them is enough to use size_t
in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With