top | item 38126045

(no title)

tleb_ | 2 years ago

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:

- Linux, compile-time checks that ptr is the same type as the member: https://elixir.bootlin.com/linux/v6.6/source/include/linux/c...

- musl, minimal: https://elixir.bootlin.com/musl/v1.2.4/source/ldso/dynlink.c...

discuss

order

No comments yet.