tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: in which we present an ugly hack to make sys/queue.h CIRCLEQ work



On Sun, Nov 24, 2013 at 06:42:40AM -0500, Mouse wrote:
> > (I think that) strict aliasing rules implies that if two types
> > "type{1,2}" do not match any of the aliasing rules (e.g. type1 is of
> > the same type as the first member of type2, or type1 is a char, or
> > ...), then any two pointers ptr{1,2} on type{1,2} respectively _ARE_
> > different, because *ptr1 != *ptr2 per the aliasing rules and this
> > implies ptr1 != ptr2.
> 
> Only if you actually evaluate *ptr1 and *ptr2 (in some cases, I think,
> just one of them is enough).  Otherwise you're not accessing the
> relevant object(s); the rule is about accesses to values, not about
> pointers that, if followed, would perform certain accesses to values.

One option would have bee to replace the comparison:
        (void *)foo == (void *)bar
with:
        (char *)foo - (char *)0 == (char *)bar - (char *)0

Which the compiler can't optimise away.
well (const char *), but that makes the line too long!

I've had to do something similar to cast to, IIRC,  (foo * const *).
In a function that advances a pointer down an array - which might be const.


        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index