Quoth Carlos R. Mafra,

switchpanel.c: In function 'wSwitchPanelSelectFirst':
switchpanel.c:673:18: warning: variable 'tmpwin' set but not used
[-Wunused-but-set-variable]
[...]
which looks bogus. Is there any compiler food for this case?

It is indeed bogus. The variable is used in WM_ITERATE_ARRAY(). However the compiler is trying very hard to be smarter than me, which isn't difficult at the best of times.

I tried declaring tmpwin as volatile but that didn't fool it. I tried initialising tmpwin explicitly but the compiler still complained that I wasn't doing anything useful with tmpwin. The only way I could silence the warning was by inserting some pointless redundant code like "if (tmpwin == wwin) tmpwin = NULL;" to fool the compiler. That's ugly and pretty stupid.

  And annoying because gcc is wrong; the variable is not unused at all.

Another answer might be to copy wwin to tmpwin then reuse wwin in WM_ITERATE_ARRAY() and return tmpwin at the end of the function. Again, inelegant as well as inconsistent with other uses of tmpwin inside iterations elsewhere in the code.

  I see three choices.

1. Wait for someone who knows more about compiler innards to tell us the "right" thing to do.

2. Accept that the code compiles with warnings on the basis that we know why the warning is issued and understand that it is not a valid complaint.

3. Burn some CPU cycles with pointless code that tricks gcc into being wrong about being wrong, therefore right.

As an aside, I compile with clang and it didn't complain, so thanks for bringing the gcc warning to my attention.


--
To unsubscribe, send mail to [email protected].

Reply via email to