This is the mail archive of the 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

malc writes:
 > On Sun, 26 Nov 2006, Andrew Haley wrote:
 > [..snip..]
 > > union
 > > {
 > >  void *barf;
 > >  void (*fptr) (void);
 > > } bilge;
 > >
 > >  bilge.barf = dlsym (NULL, "dummy");
 > >  funcs.dummy = bilge.fptr;
 > The only thing, conformance wise, that can be different here is the
 > fact that (according to the link bellow) type-prunning is allowed
 > for unions. This does not change the fact that `void *' and any
 > pointer to function are incompatible.

Are we talking ISO C or GNU C here?  This is OK for GNU C, and I think
for POSIX.

 > However i'm not targetting standard C

So why are you using -pedantic?  -pedantic is only for strict ISO C.

 > (i wouldn't know if it's possible to implement `dlsym' without
 > falling into undefined/specified behavior on such a system at all).
 > > > P.S. It seems like i can use the tripple casting trick once again
 > > >         instead of straightforward `struct.field', but this again begs
 > > >         the question of portability/conformance.
 > >
 > > Why are you using the "triple casting trick"?  All it can possibly do
 > > is silence a warning; it won't make the code correct.
 > Less typing and:

Ths one, I guess:
* 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);


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