From: Stephen D. <sd...@gm...> - 2005-06-12 05:06:58
|
On 6/11/05, Zoran Vasiljevic <zv...@ar...> wrote: > Hi >=20 > When you compile w/o debugging (i.e. with optimisation) > the GCC spits whole-lotta stuff like that: >=20 > tclthread.c:401: warning: dereferencing type-punned pointer will > break strict-aliasing rules > tclthread.c:401: warning: dereferencing type-punned pointer will > break strict-aliasing rules >=20 > The warning sems to trigger when a pointer is casted like this: >=20 > enum { > EAbsWaitIdx, EBroadcastIdx, ECreateIdx, EDestroyIdx, ESetIdx, > ESignalIdx, ETimedWaitIdx, EWaitIdx > } opt; >=20 > if (!GetArgs(interp, objc, objv, opts, 'e', ECreateIdx, > (int *) &opt, (void **) &condPtr)) { > return TCL_ERROR; >=20 > The "opt" and "condPtr" in GetArgs() are casted and it barks > at them. I cannot possibly imagine changing all code to > something like: >=20 > enum { > EAbsWaitIdx, EBroadcastIdx, ECreateIdx, EDestroyIdx, ESetIdx, > ESignalIdx, ETimedWaitIdx, EWaitIdx > } opt; > int myOpt =3D (int)opt; >=20 > if (!GetArgs(interp, objc, objv, opts, 'e', ECreateIdx, > &myOpt, (void **) &condPtr)) { > return TCL_ERROR; >=20 > This would mean lots of work and may introduce errors. >=20 > I've read that you can use (starting with gcc 3.3) -fno-strict-aliasing > which would remove those warnings. But also, somebody said that the > effect of the "-O2" is gone in such cases (haven't be able to verify) >=20 > What to do? > Any ideas? For much of the command parsing, I think something like this is fine: int opt; static CONST char *opts[] =3D { "cleanup", "list", "create", "put", "get", NULL }; enum { CCleanupIdx, CListIdx, CCreateIdx, CPutIdx, CGetIdx }; if (Tcl_GetIndexFromObj(interp, objv[1], opts, "option", 0, &opt) !=3D TCL_OK) { return TCL_ERROR; } |