X-Spam-Check-By: sourceware.org
To: cygwin@cygwin.com
From: Yitzchak Scott-Thoennes <sthoenna@efn.org>
Subject:  Re: cygwin source question
Date: Mon, 22 Jan 2007 08:19:19 +0000 (UTC)
Lines: 23
Message-ID:  <loom.20070122T085309-902@post.gmane.org>
References:  <20070121143731.GC25379@ns1.anodized.com> <009401c73d79$4cf91d40$a501a8c0@CAM.ARTIMI.COM>
Mime-Version:  1.0
Content-Type:  text/plain; charset=us-ascii
Content-Transfer-Encoding:  7bit
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Dave Korn writes:
> On 21 January 2007 14:38, Christopher Layne wrote: 
> > I notice in some places, there are double-negates, like:
> > 
> > me->read_ready |= ret || !!(events & (FD_READ | FD_ACCEPT | FD_CLOSE));
> > 
> > What's the rationale for these? To enforce either a 0 or 1, to be directly
> > in line with boolean, rather than a zero or non-zero result?
> 
>   It's a standard C idiom for that, yeh, it normalizes zero/non-zero into 0/1.

Also protects against accidentally truncating true values to false (e.g. if
events is an int and events |(FD_READ...) is 0x80000000 and me->read_ready is a
short, the implicit cast to short in the assignment turns 0x80000000 into 0).

This is also a Perl idiom (though Perl doesn't suffer the above problem).

Some people prefer (expr) ? 1 : 0, which looks a lot worse to me than !!(expr).

-- 
I'm looking for a job: http://perlmonks.org/?node=ysth#looking




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

