begin  quoting Iain Patterson as of Sat, Oct 05, 2013 at 11:36:00AM +0100:
> 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.

It's never used on the RHS of a statement, only the LHS.

The problem is the assignment. If there was no macro, you'd just use
(void) to tell the compiler and readers that you meant to ignore the
return value.

So... not-bogus.

>   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.
[snip]

4. Don't use the macro.

5. Write another macro.

-- 
SJS


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

Reply via email to