C Standard Library -
Introduction
stddef .h The header file defines various variable types and macros, which are mainly used for memory management, object sizes, pointer arithmetic, and so on.
Library variables
The variable types defined in the header file stddef.h are listed below:
| No. | Variable & Description |
|---|---|
| 1 | ptrdiff_t |
|
ptrdiff_t diff = ptr2 - ptr1; // 计算两个指针之间的差值 |
|
| 2 | **size_t ** |
|
This is an unsigned integer type; it is the sizeof result of the keyword, and is usually used to represent the size of an object or an index into an array. Its definition is implementation-dependent, typically unsigned int or unsigned long. size_t size = sizeof(int); // 获取 int 类型的大小 |
|
| 3 | **wchar_t ** |
|
This is an integer type the size of a wide character constant, used to represent multibyte characters. Its size and representation depend on the specific implementation. wchar_t wideChar = L'A'; // 宽字符常量 |
Library macros
The macros defined in the header file stddef.h are listed below:
| No. | Macro & description |
|---|---|
| 1 | NULL |
| This macro is the value of a null pointer constant. | |
| 2 | offsetof(type, member-designator) |
| This produces an integer constant of type size_t, which is the byte offset of a structure member relative to the beginning of the structure. The member is given by member-designator the second argument, and the structure's name is given in type the first argument. |