This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Tolga Dalman writes:
 > On Thu, 17 Apr 2003 18:41:49 -0400 Daniel Jacobowitz <drow at mvista dot 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 at gcc dot gnu dot org dot 

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]