Re: strict aliasing: cast from char[] or char *

2011-06-07 Thread Herman, Geza
On 06/07/2011 12:27 PM, Richard Guenther wrote: On Tue, Jun 7, 2011 at 5:51 AM, Herman, Gezag...@bitquad.com wrote: Hi, Sorry, if it has been discussed before, I found a lot of information on strict aliasing in gcc, but nothing about this particular case. I'd like to code a custom container

Re: strict aliasing: cast from char[] or char *

2011-06-07 Thread Herman, Geza
On 06/07/2011 03:02 PM, Richard Guenther wrote: On Tue, Jun 7, 2011 at 2:58 PM, Herman, Gezag...@bitquad.com wrote: On 06/07/2011 12:27 PM, Richard Guenther wrote: On Tue, Jun 7, 2011 at 5:51 AM, Herman, Gezag...@bitquad.comwrote: Hi, Sorry, if it has been discussed before, I found a

strict aliasing: cast from char[] or char *

2011-06-06 Thread Herman, Geza
Hi, Sorry, if it has been discussed before, I found a lot of information on strict aliasing in gcc, but nothing about this particular case. I'd like to code a custom container class: it has a char[] (or dynamically allocated char *) for storage, putting an element is done with placement

Re: Type-punning

2007-06-29 Thread Herman Geza
I'll try to make a simple example on which GCC produces bad code. You can find an example below. GCC-4.1 generates bad code (GCC-4.2 is fine). Neither version give a type-punning warning, though. I'm sorry that I didn't check gcc-4.2 before I started this thread. Geza Here's the code, I

Re: Type-punning

2007-06-26 Thread Herman Geza
Thanks for the answers! Why? Won't the following work? void setNaN(float v) { union { float f; int i; } t; t.i = 0x7f81; v = t.f; } As far as I know, this is guaranteed to work with GCC. But it is not kosher according to language standards, so other compilers

Re: Type-punning

2007-06-26 Thread Herman Geza
On Tue, 26 Jun 2007, Andrew Pinski wrote: On 6/26/07, Herman Geza [EMAIL PROTECTED] wrote: Maybe GCC shouldn't optimize around invalid type-punnings? That is what -fno-strict-aliasing is for. Also GCC has done this since 3.0.0 (and also 2.95 and 2.95.1 and then in 2.95.2 it was changed

Re: Type-punning

2007-06-26 Thread Herman Geza
On Tue, 26 Jun 2007, Silvius Rus wrote: Herman Geza wrote: void foo(float *a) { int *b = (int*)a; // type-punning warning // here, access to a and b shouldn't be optimized, as the compiler knows that a and b point to the same address } Is this reasonable? Even

Re: Type-punning

2007-06-26 Thread Herman Geza
On Tue, 26 Jun 2007, Silvius Rus wrote: Herman Geza wrote: aliasing when GCC (I think) incorrectly treats types different, but they're the same. For example, I have: struct Point { float x, y, z; }; struct Vector { float x, y, z; Point asPoint

Re: Type-punning

2007-06-26 Thread Herman Geza
On Tue, 26 Jun 2007 [EMAIL PROTECTED] wrote: On Tue, Jun 26, 2007 at 11:42:27PM +0200, Herman Geza wrote: struct Point { float x, y, z; }; struct Vector { float x, y, z; Point asPoint() { return reinterpret_castPoint(*this); } }; Point

Re: Type-punning

2007-06-26 Thread Herman Geza
On Tue, 26 Jun 2007, Andrew Pinski wrote: On 6/26/07, Herman Geza [EMAIL PROTECTED] wrote: Having the same layout makes them the same. Not in C or C++ and in most cases of fortran too (unless you add an attribute). Yes, it's clear now, thanks. However, it brings a new question

Type-punning

2007-06-19 Thread Herman Geza
Hi, gcc's docs states that at -fstrict-aliasing: In particular, an object of one type is assumed never to reside at the same address as an object of a different type, unless the types are almost the same. I have problems with this: struct A { float x, y; }; struct B { float