From: Mike C. <MF...@uk...> - 2008-01-03 09:32:39
|
> I wanted to try specifying the -Wstrict-alias option on the=20 > compiles per Mike Cowlishaw's suggestion, but I'm not sure this > is working. I found the warnings section in the configure.ac=20 > file and added those options there, be I don't see any evidence > that they're getting used. The g++ command lines used by the=20 > build are not showing any -W options on the line. Is there=20 > something not setup properly with the autoconfig?=20 It might be one of several things:=20 -- GCC too old (I found that 3.4.3 accepted the setting but gave no=20 warnings) =20 -- cases being missed by GCC (I typically only got a few warnings, even=20 in a source file with dozens of cases where I expected a warning, and=20 places where optimization in XLC broke the code) -- might need to enable the optimization, too; I always have=20 -fstrict-aliasing set. -- no 'bad' cases in the code. Here's a wee program that should generate the message: #include <stdio.h> int main(int argc, char *argv[]) { int u=3D0x00010002; short *s; if (argc>0) printf("%s starting...\n", argv[0]); /* quiet compiler */ s=3D(short *)&u; printf(" s=3D[%d, %d]\n", (int)s[0], (int)s[1]); return 0; } /* main */ And here's what I get during compile and run (showing the actuall GCC=20 options used [and other historical detritus]): Building strict GCC C99 [cleanObj]... Compile [strict.c]... 425 *-* comp compout||ofile sfile errdo >>> "gcc -c -DOSLINUX=3D1 -DLINUX=3D1 -O3 -march=3Di686 -DGCC = -Wall=20 -W -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wcast-align=20 -Waggregate-return -Wnested-externs -fstrict-aliasing -Wstrict-aliasing=20 -pthread -D=5FREENTRANT -std=3Dc99 -pedantic -o strict.o strict.c 2>=20 strict.err" 430 *-* typecmd errfile >>> "cat strict.err" strict.c: In function ?main?: strict.c:10: warning: dereferencing type-punned pointer will break=20 strict-aliasing rules Link [strict.o]... 490 *-* link||ofile links linklibs linkopts errdo >>> "gcc -o strict.exe strict.o -lrt -ldl -lpthread -mwindows = -mconsole 2> link.err" =20 ./strict.exe starting... s=3D[2, 1] Mike [For more info: =20 http://www.cellperformance.com/mike=5Facton/2006/06/understanding=5Fstrict= =5Faliasing.html=20 ] Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number=20 741598.=20 Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU |