This is the mail archive of the
mailing list for the GCC project.
Re: finding strict aliasing problems
- To: gdr at codesoucery dot com, lucier at math dot purdue dot edu
- Subject: Re: finding strict aliasing problems
- From: Mike Stump <mrs at windriver dot com>
- Date: Tue, 1 May 2001 19:00:22 -0700 (PDT)
- Cc: feeley at iro dot umontreal dot ca, gcc at gcc dot gnu dot org, jakub at redhat dot com, jbuck at racerx dot synopsys dot com
> From: Brad Lucier <email@example.com>
> Date: Tue, 1 May 2001 17:55:04 -0500 (EST)
> One thing I do *not* want to do is start a repeat of
> the 1999 discussion.
> But is this a problem?
> #include <stdlib.h>
> #include <stdio.h>
> foo (long int x)
> printf("%d %f\n", *((int *) x), *(double *) (((int *) x) + 1));
> long int x = (long int) malloc (sizeof(int)+sizeof(double));
> *(int *)x = 1;
> *(double *) (((int *) x) + 1) = 2.0;
> return 1;
> Here, each word of memory is accessed either as double or int. Is
> this OK?
Yes, the code is fine. Now, it is not fine to hit the double at +1 on
an int pointer. You'd have to hit an int on a +1 of a double pointer
for that to work. If your system manages the +1 to be a +2 when it
matter... then you're ok.