delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/01/22/13:24:06

X-Spam-Check-By: sourceware.org
Date: Mon, 22 Jan 2007 13:23:45 -0500 (EST)
From: Igor Peshansky <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Yitzchak Scott-Thoennes <sthoenna AT efn DOT org>
cc: cygwin AT cygwin DOT com
Subject: Re: cygwin source question
In-Reply-To: <loom.20070122T085309-902@post.gmane.org>
Message-ID: <Pine.GSO.4.63.0701221322540.18901@access1.cims.nyu.edu>
References: <loom DOT 20070122T085309-902 AT post DOT gmane DOT org>
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Mon, 22 Jan 2007, Yitzchak Scott-Thoennes wrote:

> 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).

It seems that (expr) != 0 should do the same (and is a bit more readable
than the ternary ?: operator).
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_	    pechtcha AT cs DOT nyu DOT edu | igor AT watson DOT ibm DOT com
ZZZzz /,`.-'`'    -.  ;-;;,_		Igor Peshansky, Ph.D. (name changed!)
     |,4-  ) )-,_. ,\ (  `'-'		old name: Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Freedom is just another word for "nothing left to lose"...  -- Janis Joplin

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019