C Programming/C Reference/stddef.h

From Wikibooks, open books for an open world
Jump to: navigation, 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]

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]

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]

Main page: Null pointer

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]

Main page: offsetof

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]

Main page: size_t

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]

Main page: wchar_t

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]

Main page: Pointer (computing)#C and C++

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

References[edit]

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

External links[edit]