help-gengetopt
[Top][All Lists]
Advanced

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

Re: [help-gengetopt] Re: GNU Gengetopt 2.22


From: Papp Gyozo (VBuster)
Subject: Re: [help-gengetopt] Re: GNU Gengetopt 2.22
Date: Wed, 16 Jan 2008 09:58:16 +0100

Hi

> [dereferencing type-punned pointer will break strict-aliasing rules]

I also met this warning several times in different projects but I still don't 
know by heart in what circumstances it happens for sure. But look at the GCC 
documentation: 

For C (and C++),  about -fstrict-aliasing
     
     this activates optimizations based on the type of expressions.  In
     particular, an object of one type is assumed never to reside at
     the same address as an object of a different type, unless the
     types are almost the same.  For example, an `unsigned int' can
     alias an `int', but not a `void*' or a `double'.  A character type
     may alias any other type.

You should also note that, as far as I know, this kind of data access violates 
the C99 aliasing rules. (I think mostly because of alignment and other 
size-related problems.)


>       union generic_value {
>           int int_arg;
>           char *string_arg;
>       };
> 
> for which type-punning doesn't make much sense. So I'm pretty sure
> it is harmless.

IMHO this is not the case due to the fact type-punning is not restricted to 
unions. (But you are right one of the workarounds is to use type-pun unions 
with all types possibly to use.) However the warning here may be harmless 
probably.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]