forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 1
Shifted Pointers
widberg edited this page Sep 6, 2023
·
6 revisions
offsetof
__builtin_offsetof
CONTAINING_RECORD
typedef struct vec3f {
float x;
float y;
float z;
} vec3f_t;
typedef struct player {
char name[16];
int health;
int armor;
int ammo;
vec3f_t position;
} player_t;
const char *get_player_name_from_shifted_pos_pointer(const vec3f_t *__shifted(player_t, 0x1C) pos) {
return ADJ(pos)->name;
}
const vec3f_t *__shifted(player_t, __builtin_offsetof(player_t, position)) pos
CONTAINING_RECORD(pos, player_t, position)
#define ADJ(value) ((__parentof(value) *)((char *)(value) - __deltaof(value)))