[postgis-devel] Fixed "strict-aliasing rule break"s
strk at refractions.net
strk at refractions.net
Mon Jan 9 03:55:10 PST 2006
I think I finally got the problem with the
"casting type-punned pointer will break strict-aliasing rule"
warning raised by gcc-3.3 up.
If I got it correctly this is a type-punned pointer:
POINT4D p;
POINT2D *p2 = (POINT2D *)&p; // &p is type-punned
There must be a "strict" rule saying you cannot cast
these kind of pointers (directly derived from a variable's address).
This syntax fixes the warning by using an intermediate
pointer which is thus no-more "type-punned":
POINT4D p;
POINT4D *p_ptr = &p; /* use a "real" pointer rather then
* a "type-punned" one
*/
/* No cast the "real pointer" */
POINT2D *p2 = (POINT2D *)p_ptr;
I guess the rule is there to allow for shifting pointer value
based on memory alignment constraints, but I'm not that much
into gcc algorithms to tell.
Anyway, using these intermediate pointers removes the last
warnings left on user code at least on my machine, using -Wall.
Other warnings are from shapelib and generated parser:
lex.yy.c:3044: warning: `yyunput' defined but not used
shpopen.c:176: warning: `rcsid' defined but not used
dbfopen.c:200: warning: `rcsid' defined but not used
If you have suggestions about them let me know.
Thanks.
--strk;
/"\ ASCII Ribbon Campaign
\ / Respect for low technology.
X Keep e-mail messages readable by any computer system.
/ \ Keep it ASCII.
More information about the postgis-devel
mailing list