stddef.h(0P)

πŸŽ€ PROLOG πŸŽ€

ok so before we even get into it: this manual page is part of the POSIX Programmer's Manual. but bestie, heads up β€” the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. πŸ’€


✨ NAME ✨

stddef.h β€” standard type definitions. literally the blueprint of "what even is a pointer difference" πŸ’…


🌸 SYNOPSIS 🌸

#include <stddef.h>

that's it. that's the whole vibe. one include and you're in. 🫢


πŸ’– DESCRIPTION πŸ’–

so everything described on this reference page is aligned with the ISO C standard. and like, any conflict between the requirements described here and the ISO C standard? not intentional, bestie, we promise. this volume of POSIX.1‐2017 defers to the ISO C standard. periodt.

the <stddef.h> header shall define the following macros:

  • NULL β€” the null pointer constant. this macro shall expand to an integer constant expression with the value 0 cast to type void *. yes, the cast is the whole point, iykyk.
  • offsetof(type, member-designator) β€” an integer constant expression of type size_t, whose value is the offset in bytes to the structure member (member-designator), measured from the beginning of its structure (type). it's giving "where am i in this struct" energy. πŸ¦‹

and the <stddef.h> header shall also define the following types:

  • ptrdiff_t β€” signed integer type of the result of subtracting two pointers. subtraction but make it a type. 😌
  • wchar_t β€” integer type whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales; the null character shall have the code value zero. each member of the basic character set shall have a code value equal to its value when used as the lone character in an integer character constant if an implementation does not define __STDC_MB_MIGHT_NEQ_WC__. okay that last part is very specific and we are keeping every word of it. πŸ‘‘
  • size_t β€” unsigned integer type of the result of the sizeof operator. the icon. the moment. the legend.

and here's a thing the implementation shall do: support one or more programming environments in which the widths of ptrdiff_t, size_t, and wchar_t are no greater than the width of type long. and if you wanna know the names of these programming environments? you can get them using the confstr() function or the getconf utility. 🧚

the following sections are informative. (translation: the real rules already happened, this is the commentary track ✨)

🌈 APPLICATION USAGE 🌈

None.

like, genuinely none. nothing to say. no notes. πŸ’…


πŸ’œ RATIONALE πŸ’œ

ok so the tea: the ISO C standard does not require the NULL macro to include the cast to type void *, and it specifies that the NULL macro be implementation-defined.

but POSIX.1‐2008 requires the cast β€” and therefore it need not be implementation-defined. slay, honestly. POSIX said "we'll take it from here." 🫢


⭐ FUTURE DIRECTIONS ⭐

None.

the future is, apparently, exactly the same. iconic behavior. 🌸


πŸ¦‹ SEE ALSO πŸ¦‹

  • <sys_types.h>, <wchar.h>
  • The System Interfaces volume of POSIX.1‐2017, confstr()
  • The Shell and Utilities volume of POSIX.1‐2017, getconf

portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (yes, the original is the main character here, not this page. respect.) the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .

ngl if something looks cursed in here it's probably a conversion glitch, not a design choice πŸ’€

and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017, filed under stddef.h(0P) β€” go forth and offsetof responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from