1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-13 04:39:36 +00:00

Use __builtin_offsetof for non IDO builds (#1140)

* Add offsetof macro

* Change old uses of OFFSETOF with offsetof
This commit is contained in:
Anghelo Carvajal 2022-02-13 02:05:11 -03:00 committed by GitHub
parent ed0daabf98
commit 2191c8b0a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 11 deletions

View file

@ -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)

View file

@ -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

View file

@ -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))

View file

@ -74,13 +74,13 @@ typedef struct {
#define SLOT_SIZE (sizeof(SaveContext) + 0x28)
#define CHECKSUM_SIZE (sizeof(Save) / 2)
#define DEATHS OFFSETOF(SaveContext, deaths)
#define NAME OFFSETOF(SaveContext, playerName)
#define N64DD OFFSETOF(SaveContext, n64ddFlag)
#define HEALTH_CAP OFFSETOF(SaveContext, healthCapacity)
#define QUEST OFFSETOF(SaveContext, inventory.questItems)
#define DEFENSE OFFSETOF(SaveContext, inventory.defenseHearts)
#define HEALTH OFFSETOF(SaveContext, health)
#define DEATHS offsetof(SaveContext, deaths)
#define NAME offsetof(SaveContext, playerName)
#define N64DD offsetof(SaveContext, n64ddFlag)
#define HEALTH_CAP offsetof(SaveContext, healthCapacity)
#define QUEST offsetof(SaveContext, inventory.questItems)
#define DEFENSE offsetof(SaveContext, inventory.defenseHearts)
#define HEALTH offsetof(SaveContext, health)
#define SLOT_OFFSET(index) (SRAM_HEADER_SIZE + 0x10 + (index * SLOT_SIZE))

View file

@ -1,12 +1,13 @@
#ifndef _FILE_CHOOSE_H_
#define _FILE_CHOOSE_H_
#include "libc/stddef.h"
#include "ultra64.h"
#include "global.h"
#include "vt.h"
#define GET_NEWF(sramCtx, slotNum, index) (sramCtx->readBuff[gSramSlotOffsets[slotNum] + OFFSETOF(SaveContext, newf[index])])
#define GET_NEWF(sramCtx, slotNum, index) (sramCtx->readBuff[gSramSlotOffsets[slotNum] + offsetof(SaveContext, newf[index])])
#define SLOT_OCCUPIED(sramCtx, slotNum) \
((GET_NEWF(sramCtx, slotNum, 0) == 'Z') || \