The <cstddef>
header is a wrapper for the C standard <stddef.h>
header, which declares a few types and macros.
The C header declares the wchar_t
type, but wchar_t
is a reserved keyword in C++, so there is no need to #include
<cstddef>
to declare this type.
Null pointer
#define NULL 0
The NULL
macro expands to the integer 0, which represents a null pointer.
Some C libraries declare NULL
as (void*)0
in stddef.h. This definition is wrong for C++. Most C++ compilers correctly declare NULL
as 0
, but if you are using an old compiler or library, it might contain an incorrect declaration of NULL
.
Member offset
size_t offsetof(type, member-name)
The offsetof
macro returns the offset in bytes of a member of a struct
as a constant integer. The type must be a plain C-style struct
(plain old data), and the expression &(t.
member-name)
must be an address constant where t
is an instance of type. In particular, this means the member-name must not be a bitfield, a static member, or a function member.
Pointer difference
typedef ... ptrdiff_t
The ptrdiff_t
type is a signed integral type that represents the difference between two pointers. The exact type is implementation defined.
sizeof result type
typedef ... size_t
The size_t
type is the type of the result of the sizeof
operator. It is an unsigned integral type. The exact type is implementation-defined.