stddef.h is a standard C header file that defines a few important macros and typedefs. Many other C headers files, such as stdio.h and stdlib.h, already include stddef.h so it isn't often included on its own. Unlike many other header files, stddef.h is guaranteed to be present even in a freestanding implementation where there is no C library. This is usually only the case with extremely low-level programming environments, such as for embedded microcontrollers.

It defines these macros:

  • NULL is the ubiquitous NULL pointer, which will typically be defined as 0 or ((void *)0)
  • offsetof is a simple macro for determining the offset in bytes of a member variable from the beginning of a struct; the return type is of size_t.

It also defines these typedefs:

  • ptrdiff_t is signed integer type that should be used for representing the difference between two pointers.
  • size_t is an unsigned integer type that should be used for representing the size of objects; the sizeof operator returns a size_t value.
  • wchar_t is a wide character type that can be used for representing character sets larger that one-byte per character.

Log in or register to write something here or to contact authors.