From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: GNAT 4.4.5 order of conditional processing?
Date: Tue, 15 Nov 2011 16:08:37 -0700
Date: 2011-11-15T16:08:37-07:00 [thread overview]
Message-ID: <j9urg4$cke$1@tornado.tornevall.net> (raw)
In-Reply-To: <fedec493-c81e-4bc9-ba94-399028221f77@k26g2000yqd.googlegroups.com>
On 11/15/2011 01:30 PM, awdorrin wrote:
> Given an IF statement such as the following:
>
> if X = Y and not A and B
>
> How does GNAT handle the processing of the conditional statements?
> Will "X = Y" be processed first, and if false, will the rest be
> skipped?
The language specifies that all the conditions must be evaluated. A compiler
that does differently isn't Ada.
To skip later conditions, use the "short-circuit" forms "and then" and "or else":
if P /= null and then P.all = Sentinel then
if P = null or else P.all = Sentinel then
Note that the short circuit forms should not be considered optimizations. With
modern processors, unnecessary short-circuit forms may sometimes be slower than
the regular equivalents.
--
Jeff Carter
"I feel as though somebody stepped on my tongue
with muddy feet."
Never Give a Sucker an Even Break
112
next prev parent reply other threads:[~2011-11-15 23:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-15 20:30 GNAT 4.4.5 order of conditional processing? awdorrin
2011-11-15 20:54 ` Niklas Holsti
2011-11-15 21:07 ` awdorrin
2011-11-15 21:23 ` Vinzent Hoefler
2011-11-15 21:49 ` awdorrin
2011-11-16 21:31 ` Gautier write-only
2011-11-16 22:40 ` Adam Beneschan
2011-11-17 0:00 ` Adam Beneschan
2011-11-15 23:08 ` Jeffrey Carter [this message]
2011-11-16 1:18 ` Adam Beneschan
2011-11-16 5:33 ` tmoran
2011-11-16 17:52 ` awdorrin
2011-11-16 20:01 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox