C Programming/stddef.h

From Wikibooks, open books for an open world
Jump to navigation Jump to search

stddef.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[1].

Inclusion[edit | edit source]

In C, one includes the header file "stddef.h", in this way:

#include <stddef.h>

In C++, one includes the header file "cstddef", in this way:

#include <cstddef>

Namespace[edit | edit source]

The header file "stddef.h" places its definitions in the global scope; the header file "cstddef" places size_t and ptrdiff_t in namespace std.

NULL[edit | edit source]

A macro that expands to a null pointer constant. It may be defined as ((void*)0), 0 or 0L depending on the compiler and the language.

offsetof(type, member)[edit | edit source]

A functional macro that is used to determine the byte offset of the indicated member field in the specified structure type.

Type size_t[edit | edit source]

The type size_t represents the appropriate type for representing the size of objects of memory areas, and for use in dereferencing the elements of an array. It has an implementation-dependent size; usually but not necessarily, it has a 32-bit representation on 32-bit systems and a 64-bit representation on 64-bit systems. It is unsigned.

This type has in some implementations a signed variant with name ssize_t, that is defined in the UNIX header file "unistd.h". For GNU C the type ssize_t is defined in "stddef.h" and thus resides in the same file as size_t.

Type wchar_t[edit | edit source]

An implementation-specific "wide character" type, which is predefined in the C++ programming language but requires the header "stddef.h" or "wchar.h" in the C programming language.

Type ptrdiff_t[edit | edit source]

The type ptrdiff_t is a type that can hold the result of subtracting two pointers which point to two items of the same object. The underlying type of ptrdiff_t varies from implementation to implementation.

A Object is maybe bigger than PTRDIFF_MAX. A subtracting of two pointers which have a bigger difference than PTRDIFF_MAX / PTRDIFF_MIN result in a undefined behavior.

References[edit | edit source]

  1. http://pubs.opengroup.org/onlinepubs/7908799/xsh/stddef.h.html

External links[edit | edit source]