Sujet : Re: Shortcut Booleans
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 10. Jun 2024, 03:24:22
Autres entêtes
Organisation : None to speak of
Message-ID : <87jzix7cx5.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Lawrence D'Oliveiro <
ldo@nz.invalid> writes:
On Sun, 9 Jun 2024 13:35:12 +0200, David Brown wrote:
In general, it would be inconvenient if you did not know whether "a @ b"
was going to evaluate "b", including all function calls and
side-effects.
>
Ada has “and then” and “or else”, so that you can specifically request
shortcut evaluation when program correctness depends on it, and leave it
up to the implementation otherwise.
Note that Ada's "and" and "or" operations are required to evaluate both
operands; it isn't up to the implementation to decide to short-circuit
them (except when it doesn't change the program's behavior, like any
other optimization).
This principle could be extended to other situations ...
Yes, it could, but I don't think it would be worthwhile for operations
other than "and" and "or".
Do you have examples that are compelling enough to justify a new
language feature, especially given that you can already write
(x == 0 ? 0 : x * y)?
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */