tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: style: structures
> C99 Sec. 6.7.2.1 `Structure and union specifiers', clause 13, p. 103:
> [...]
Ah! Thank you. Yes, that is what I was looking for. (And the "vice
versa" answers the question I asked in my previous mail.)
> But don't use casts for this -- use container_of, which is more
> flexible and checks types better than a cast does.
But less portable. (For example, in my 5.2, I find only one .h file
defining container_of, and that one is a device-specific file in
sys/dev/pci/. And on a modern Ubuntu work machine, the only .h
under /usr/include which even _mentions_ container_of is
/usr/include/valgrind/pub_tool_basics.h - but I don't really understand
Linux; this could be justified for all I know.)
Of course, depending on what the code in question is for, portability
may or may not be reason enough to use casts instead. Since the
question was originally about NetBSD style, probably not in that case.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index