Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce pollution in stddef.h and stdarg.h #1595

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
stddef.h: don't include sys/cdefs.h
Switch to sys/_visible.h for visibility macros.

Prefer __builtin_offsetof over __offset.  sys/cdefs.h always defines
__offsetof to __builtin_offsetof so just use the latter to remove a
dependency on sys/cdefs.h.  Realistically, we're never going to care
about a compiler that doesn't supply this builtin.

Add a somewhat questionable guard around the offsetof() definition
because the compiler no longer thinks it the same as a number of other
redundent definitions scattered around (e.g., in the openzfs codebase).
It is infact the same and those defintions likely shouldn't exist at
all.
brooksdavis committed Feb 6, 2025
commit 7febc2df6554e85e28013ae97871ec5eef24e36c
6 changes: 4 additions & 2 deletions include/stddef.h
Original file line number Diff line number Diff line change
@@ -32,9 +32,9 @@
#ifndef _STDDEF_H_
#define _STDDEF_H_

#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
#include <sys/_visible.h>

#ifndef _PTRDIFF_T_DECLARED
typedef __ptrdiff_t ptrdiff_t;
@@ -61,7 +61,9 @@ typedef __max_align_t max_align_t;
#endif
#endif

#define offsetof(type, field) __offsetof(type, field)
#ifndef offsetof
#define offsetof(type, field) __builtin_offsetof(type, field)
#endif

#if __EXT1_VISIBLE
/* ISO/IEC 9899:2011 K.3.3.2 */