C Standard Library -<stddef.h>
Introduction
stddef .hThe header file defines various variable types and macros, which are mainly used for memory management, object size, and pointer arithmetic.
Library variables
The following are the variable types defined in the header file stddef.h:
| Serial Number | Variables & Descriptions |
|---|---|
| 1 | ptrdiff_t
ptrdiff_t diff = ptr2 - ptr1; // 计算两个指针之间的差值 |
| 2 | size_t This is an unsigned integer type, which issizeofthe result of a keyword, usually used to represent the size of an object or the index of an array. Its definition is implementation-dependent, usually unsigned int or unsigned long. size_t size = sizeof(int); // 获取 int 类型的大小 |
| 3 | wchar_t This is an integer type for 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 following are the macros defined in the header file stddef.h:
| Serial Number | Macros & Descriptions |
|---|---|
| 1 | NULL This macro is the value of a null pointer constant. |
| 2 | offsetof(type, member-designator) This generates 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 specified bymember-designatorGiven, the name of the structure istypegiven in. |