This is usually called container_of in C projects. It is compile-time safe as well, though the error won't be pretty. Linux, Qemu, musl, U-Boot, iproute2 & uclibc-ng each have a copy from the few project I've looked at. Two interesting implementations: