[haiku-commits] Re: r40399 - in haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/imap: . imap_lib

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 09 Feb 2011 13:50:30 +0100

On 2011-02-09 at 13:08:38 [+0100], Jérôme Duval <korli@xxxxxxxxxxxxxxxx> 
wrote:
> 2011/2/9 Oliver Tappe <zooey@xxxxxxxxxxxxxxx>:
> > On 2011-02-09 at 11:26:00 [+0100], Jérôme Duval <korli@xxxxxxxxxxxxxxxx>
> > wrote:
> > [ ... ]
> >>
> >> > +void
> >> > +FolderConfigWindow::_ApplyChanges()
> >> > +{
> >> > +       bool haveChanges = false;
> >> > +       for (unsigned int i = 0; i < fFolderList.size(); i++) {
> >> > +               FolderInfo& info = fFolderList[i];
> >> > +               CheckBoxItem* item =
> >> > (CheckBoxItem*)fFolderListView->ItemAt(i);
> >> > +               if ((info.subscribed && !item->Checked())
> >> > +                       || (!info.subscribed && item->Checked())) {
> >> > +                       haveChanges = true;
> >>
> >> This check could be better written : if (info.subscribed ^ 
> >> item->Checked())
> >
> > Hm, while that might be more readable, it's a bit dangerous, since ^ is
> > *bitwise* exclusive or, so it relies on both arguments being boolean 
> > values
> > in order to work as intended in this context. That may be the case here,
> > though, I just can't judge from the code above.
> 
> Sure, one can add a logical negation to force boolean values :)
> if (!info.subscribed ^ !item->Checked())

This is convoluted. Rather explicitly cast to bool -- though that is 
superfluous, even if one argument is non-bool, as long as only bool values 
are assigned. Moreover, the ^ operator promotes both arguments to int and 
has a result of type int. As per our convention the result would have to be 
compared to 0 to turn it into a boolean:

  if ((info.subscribed ^ item->Checked()) != 0)

I'd recommend to use the != operator instead, though.

CU, Ingo

Other related posts: