Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C, you can use a bit of macro trickery to get the same safety, e.g: by defining a 0-sized array of the some type alongside the intrusive node. Then, macros that do the "cast down" from the intrusive node to the container element can also do a type-comparison (using some trickery) between the anchor's array and the container type.

I've seen it implemented, but everyone uses the typical non-type-safe one anyway :)

I don't think I've ever had such bugs in a lot of code though, since I tend to wrap the "containerof" call with a little function like: foo_of_lru_entry and foo_of_hash_entry. A bit of boilerplate for each data structure, but worth it.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: