diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2022-02-13 02:05:11 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-13 00:05:11 -0500 |
| commit | 2191c8b0a073cf58a5106bd3055fb276eead8b83 (patch) | |
| tree | 130eca1b72e156fb288f890ce3d5ca1e69582a65 /include | |
| parent | ed0daabf98a92ab0232dcfb9ea071bd3411b762e (diff) | |
Use `__builtin_offsetof` for non IDO builds (#1140)
* Add offsetof macro
* Change old uses of OFFSETOF with offsetof
Diffstat (limited to 'include')
| -rw-r--r-- | include/ichain.h | 4 | ||||
| -rw-r--r-- | include/libc/stddef.h | 6 | ||||
| -rw-r--r-- | include/macros.h | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/include/ichain.h b/include/ichain.h index 37af91057..07bd07313 100644 --- a/include/ichain.h +++ b/include/ichain.h @@ -1,6 +1,8 @@ #ifndef ICHAIN_H #define ICHAIN_H +#include "libc/stddef.h" + typedef struct { u32 cont: 1; u32 type: 4; @@ -36,7 +38,7 @@ typedef enum { * * cont ----- ICHAIN_CONTINUE (or ICHAIN_STOP) to continue (or stop) parsing */ #define ICHAIN(type, member, value, cont) \ - { cont, type, OFFSETOF(Actor, member), value } + { cont, type, offsetof(Actor, member), value } #define ICHAIN_U8(member, val, cont) ICHAIN(ICHAINTYPE_U8, member, val, cont) #define ICHAIN_S8(member, val, cont) ICHAIN(ICHAINTYPE_S8, member, val, cont) diff --git a/include/libc/stddef.h b/include/libc/stddef.h index ac71ed362..b8c9859b0 100644 --- a/include/libc/stddef.h +++ b/include/libc/stddef.h @@ -7,4 +7,10 @@ typedef unsigned long size_t; typedef unsigned int uintptr_t; +#ifdef __GNUC__ +#define offsetof(structure, member) __builtin_offsetof (structure, member) +#else +#define offsetof(structure, member) ((size_t)&(((structure*)0)->member)) +#endif + #endif diff --git a/include/macros.h b/include/macros.h index b979dd129..a919de427 100644 --- a/include/macros.h +++ b/include/macros.h @@ -8,8 +8,6 @@ #define VIRTUAL_TO_PHYSICAL(addr) (u32)((u8*)(addr) - 0x80000000) #define SEGMENTED_TO_VIRTUAL(addr) PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)] + SEGMENT_OFFSET(addr)) -#define OFFSETOF(structure, member) ((size_t)&(((structure*)0)->member)) - #define SQ(x) ((x)*(x)) #define ABS(x) ((x) >= 0 ? (x) : -(x)) #define DECR(x) ((x) == 0 ? 0 : --(x)) |
