This is the mail archive of the gcc-help@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: Strict aliasing and pointers to functions


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.


> 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.


[..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.

--
vale


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