This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Strict aliasing and pointers to functions
malc writes:
> On Sun, 26 Nov 2006, Andrew Haley wrote:
>
>
> [..snip..]
>
> > Are we talking ISO C or GNU C here? This is OK for GNU C, and I think
> > for POSIX.
>
> You mentioned ISO C a few times. So i'd guess we are talking c89.
OK. I don't think it matters: the rules of C89 and C99 are not
substantially different in this area.
> > > However i'm not targetting standard C
> >
> > So why are you using -pedantic? -pedantic is only for strict ISO C.
>
> Because i happen to compile with 5-6 versions of gcc on different
> platforms with different ideas of what -W[xxx] turns on and throwing
> `-pedantic' into the mix generally turns on more.
Sure, it does, but why do you want them? They're not going to make
your programs any better.
> [..snip..]
>
> > ...
> > * The cast below is the correct way to handle the problem.
> > * The (void *) cast is to avoid a GCC warning like:
> > * "warning: dereferencing type-punned pointer will break \
> > * strict-aliasing rules"
> > * which is wrong this code. (void *) introduces a compatible
> > * intermediate type in the cast list.
> > */
> > count -= got, *(char **)(void *)&buffer += size * got;
> >
> > I'm not convinced this hackery is correct by my reading of ISO C, and
> > in any case it's pointless. It could be replaced by:
> >
> > count -= got, buffer = (char*)buffer + (size * got);
>
> That's not for me to decide, not a language layer by any stretch of
> imagination.
I don't understand this remark.
Andrew.