C sizeof and offsetof Implementation

C has no internal reflection. Which basically means that given a raw pointer there is no way to infer anything about it at runtime. We can’t know if it’s size, what type it is, etc. If it’s a struct we don’t even know

The C sizeof macro.

#define sizeof(t) (char *)(&t + 1) - (char *)(&t)

The C offset macro.

#define offsetof(t, m) (size_t)&(((t *)0)->m)