On 6/11/05, Zoran Vasiljevic <[EMAIL PROTECTED]> wrote:
> Hi
>
> When you compile w/o debugging (i.e. with optimisation)
> the GCC spits whole-lotta stuff like that:
>
> 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
>
> The warning sems to trigger when a pointer is casted like this:
>
> enum {
> EAbsWaitIdx, EBroadcastIdx, ECreateIdx, EDestroyIdx, ESetIdx,
> ESignalIdx, ETimedWaitIdx, EWaitIdx
> } opt;
>
> if (!GetArgs(interp, objc, objv, opts, 'e', ECreateIdx,
> (int *) &opt, (void **) &condPtr)) {
> return TCL_ERROR;
>
> The "opt" and "condPtr" in GetArgs() are casted and it barks
> at them. I cannot possibly imagine changing all code to
> something like:
>
> enum {
> EAbsWaitIdx, EBroadcastIdx, ECreateIdx, EDestroyIdx, ESetIdx,
> ESignalIdx, ETimedWaitIdx, EWaitIdx
> } opt;
> int myOpt = (int)opt;
>
> if (!GetArgs(interp, objc, objv, opts, 'e', ECreateIdx,
> &myOpt, (void **) &condPtr)) {
> return TCL_ERROR;
>
> This would mean lots of work and may introduce errors.
>
> 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)
>
> What to do?
> Any ideas?
For much of the command parsing, I think something like this is fine:
int opt;
static CONST char *opts[] = {
"cleanup", "list", "create", "put", "get", NULL
};
enum {
CCleanupIdx, CListIdx, CCreateIdx, CPutIdx, CGetIdx
};
if (Tcl_GetIndexFromObj(interp, objv[1], opts, "option", 0, &opt)
!= TCL_OK) {
return TCL_ERROR;
}