Hi,

this is the cpp code:

---8<---
 if (panel->win) {
  for (tmpwin = WMArrayFirst(panel->windows, &(i)); (i) != WANotFound; tmpwin = 
WMArrayNext(panel->windows, &(i))) {
   changeImage(panel, i, i == panel->current, 0, 0);
  }
  drawTitle(panel, panel->current, title);
 }
---8<---

The tmpwin variable is assigned, but not used. IMO, the gcc warning (is a 
warning, no an error) is right.

The question is... could we change something? tmpwin->current is equal to 
tmpwin? (I don't know).

Iain, good patches :-)
kix


On Sat, 05 Oct 2013, Iain Patterson escribió:

> 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 wmaker-dev-unsubscr...@lists.windowmaker.org.

-- 
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to