Re: Strict aliasing and pointers to functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux