Re: strict aliasing (again)

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

 



Mojmir Svoboda wrote:
> * Andrew Haley <aph@xxxxxxxxxx> [2008-12-02 13:32:46 +0000]:
> 
>> It's undefined behaviour: if you make a pointer by taking the address of an
>> object you can dereference that pointer.  If it's a pointer to an array
>> you can also increment it up to one past the end of that array.  You
>> can only dereference that pointer if it points to the object you
>> took the address of.
> 
> acknowledged.
> 
>> In this case it'll probably work as long as there is no padding between
>> x, y, and z.
>> But it's not well-defined code.
> 
> and that is exactly why i want to fix it. as i pointerd out to John: like
> this i have to go to forums and ask whether this is safe on gcc and then
> go to msvc and ask what about their compiler. 
> 
> for example i asked whether the "union_cast" works on the msvc and still
> the responses were quite foggy, so i don't know really even now.

That's an interesting one.  We advertise that as a fully-supported
gcc extension and as far as I know it works everywhere, but you
never know, it might not.

> i find this programming style quite uncomfortable...
> 
>> OK, I see.  I guess you'll have to proceed slowly, but IMO there is no
>> point replacing one case of undefined behaviour with another.  If you're
>> going to fix it, you might as well fix it right.
> 
> okay, i am moving to "do you know a good basic linear algebra" mailing
> list :)

Okay, your call.  I'm not as pessimistic as John fine regarding "throw
out the whole mess of code and rewrite from scratch" because I have
had to repair code like this, but good luck whatever you decide.

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux