delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/17/16:20:14

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Thanks, HELP! mouse problems
Date: 17 May 1997 15:10:22 GMT
Organization: Oxford University, England
Lines: 35
Distribution: world
Message-ID: <5lkhou$s3o@news.ox.ac.uk>
References: <01bc6257$9ed88cc0$LocalHost AT stachowiak> <Ea$OfDAm4SfzEwsK AT jenkinsdavid DOT demon DOT co DOT uk>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

David Jenkins (me AT jenkinsdavid DOT demon DOT co DOT uk) wrote:
: In article <01bc6257$9ed88cc0$LocalHost AT stachowiak>, Helix
: >
: >  if ((mouse_b & 1) & (mouse_x > fx) & (mouse_x < lx) & (mouse_y > fy) &
: >(mouse_y < ly))
: >   CityBackPix();

: Why do you have each condition in () brackets??

I'm not sure exactly what the precedence is, but I do that too for
clarity.

: And why only the one &'s I thought your HAD to use two &&????

A single & means `bitwise AND'; the double && means logical AND. As an
example, 0 & 1 == 0, 1 & 3 == 1, 5 & 12 == 4, while x && y == 1 iff both x
and y are non-zero. I'm not sure this is very clear; the bitwise AND
returns a 1 in each bit position where that bit in both arguments is set,
while the logical AND returns either TRUE iff both arguments are not
FALSE, otherwise it returns FALSE.

In this case, the line should really read:

if ((mouse_b & 1) && (mouse_x > fx) && (mouse_x < lx)
                  && (mouse_y > fy) && (mouse_y < ly)) {...}

(aligned for clarity). The first remains bitwise because its purpose is to
extract the bottom bit of mouse_b. All the others are relating to whether
the comparisons are non-zero. The line would actually work as it was
originally written, but it would probably fail if more than one of the
conditions was not a TRUE/FALSE value.

-- 
George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Merton College, Oxford

- Raw text -


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