delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/05/09:55:04

From: Nathan_Johnson AT mail DOT tmmna DOT com
To: djgpp AT delorie DOT com
Message-ID: <852564EA.004B7F0B.00@mail.tmmna.com>
Date: Tue, 5 Aug 1997 09:52:31 -0400
Subject: djgpp daily digest for 04 Aug 1997 2/4
Mime-Version: 1.0







==============
 Chad Catlett
 dwi AT netc DOT com
==============

------------------------------

From: "Art S. Kagel" <kagel AT bloomberg DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Newbie Question: Index lookup coord. checking...
Date: Fri, 1 Aug 1997 09:55:53 -0400
Message-ID: <Pine DOT D-G DOT 3 DOT 91 DOT 970801095031 DOT 16551D-100000 AT dg1>
NNTP-Posting-Host: 160.43.8.60
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
In-Reply-To: <5rif6n$5v1 AT news DOT velocity DOT net>
To: djgpp AT delorie DOT com
Precedence: bulk

On Mon, 28 Jul 1997, Badman wrote:

> Hello, I have a simple question: Can you check coordinates for an index
> lookup (so you don't get an error) and check that same index in the same
> if() statement?
>
> For example:
> if (x > 0 && x < 640 && y > 0 && y < 480 && *(screen+(y * 640)+x) > 3){
>
>    /* do stuff */
> };
>
> or....
>
>
> if (x > 0 && x < 640 && y > 0 && y < 480){
>   if (*(screen+(y * 640)+x)>3){
> };
> };
>
> which is better? Any help would be appreciated...

Both are good in the sense that both will work exactly the same way.
^^^^^^^^^^^^^^^^^^^^^^^^^^                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This isn't necessarily true.  I think that this is compiler /
system dependant.  It is a whole lot safer to break this comparison, and
like you said, makes it much easier to read.  Sometimes when using the
Borland
compiler, I got some strange results that seemed to point to the order that

comparisons in if statements actually followed didn't necessarily follow
the
order that I had coded them in.  Maybe it has something to do with
optimization?


- Raw text -


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