type aliasing (was: gcc 3.3 -03 produces bad code)

Andrew Haley aph@redhat.com
Fri Apr 18 10:41:00 GMT 2003


Tolga Dalman writes:
 > On Thu, 17 Apr 2003 18:41:49 -0400 Daniel Jacobowitz <drow@mvista.com> wrote:
 > 
 > > If you use "char *", that's not an aliasing violation.  It's often not
 > > the best way to do it, but it's not an aliasing violation.
 > 
 > sorry for insisting, but what is it then? my example was not meant to be a
 > "char*", but how about:
 > 
 > uint32_t i = /* a value */;
 > uint8_t  l; 
 > 
 > l = ((uint8_t*) &i)[1];
 > 
 > would that be a violation?

Yes.

 > or this one:
 > 
 > char* c = "teststring";
 > int* p;
 > 
 > for (p = (int*) c; p; p++) {
 >      /* do something */
 > }

Yes.

This isn't the place to have this discussion.  For information about
type based optimization, please read
http://www.ddj.com/documents/s=880/ddj0010d/0010d.htm.  Please also
note that if you want to access data via an lvalue of a different
type, use a union.

Redirected to gcc-help@gcc.gnu.org.

Andrew.



More information about the Gcc mailing list