On Thu, Nov 21, 2013 at 08:55:44AM -0500, Ken Hornstein wrote: > >On Wed, Nov 20, 2013 at 07:01:15PM -0500, Ken Hornstein wrote: > > > #define TAILQ_PREV(elm, headname, field) \ > > > (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) > > > >There's another wrinkle, however, which is that this code (TAILQ_PREV) > >also violates the strict-aliasing rules. I don't think anyone has > >found a clear case of gcc (4.8 or otherwise) tripping on it yet, but > >it too really ought to be fixed before it bites someone. > > I'll be the first one to admit that the strict-aliasing rules are just > at the limit of my understanding ...
Modulo some administrative details, it's just "no object in memory may be accessed using more than one type". > but doesn't that depend on how you use it? Not in this case; the problem is that the cast to struct headname causes it to read tqh_last from an item in memory that might be a queue head but is probably actually a queue element. As for getting bitten by the violation... that depends on the compiler doing something that depends on the assumption that you didn't make such an access. -- David A. Holland dholl...@netbsd.org