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 Content-type: text/plain; charset=us-ascii Precedence: bulk ============== Chad Catlett dwi AT netc DOT com ============== ------------------------------ From: "Art S. Kagel" Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie Question: Index lookup coord. checking... Date: Fri, 1 Aug 1997 09:55:53 -0400 Message-ID: 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?