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 NumberVariables & Descriptions
1ptrdiff_t

ptrdiff_tIt is a signed integer type used to represent the difference between two pointers. Its definition also depends on the implementation, typically beingintorlong。

ptrdiff_t diff = ptr2 - ptr1; // 计算两个指针之间的差值
2size_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 类型的大小
3wchar_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 NumberMacros & Descriptions
1NULL
This macro is the value of a null pointer constant.
2offsetof(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.
other extensions