Opaque ptr to struct ptr

Run Settings
LanguageC++
Language Version
Run Command
#include <stdint.h> #include <stdlib.h> #include <stdio.h> #define OFFSET_MEMBER(type, member) ((size_t)(&((type *)0)->member)) #define PTR_STRUCT_BASE_FROM_MEMBER(type, member, value) ((type *)((size_t)(value) - OFFSET_MEMBER(type, member))) struct bah{ int member1; size_t member2; }; int main() { bah thing = {91, 32}; void *opaque = &thing.member2; bah *pointer_to_thing_from_opaque_ptr = PTR_STRUCT_BASE_FROM_MEMBER(bah, member2, opaque); printf("%zu\n", pointer_to_thing_from_opaque_ptr->member2); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines