Sujet : Re: Shortcut Booleans
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 09. Jun 2024, 12:35:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4441g$3f1d5$2@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 08/06/2024 04:42, Lawrence D'Oliveiro wrote:
On Fri, 7 Jun 2024 13:41:06 +0100, bart wrote:
Common sense applies, otherwise you could shortcut these operations:
>
a * b // when a is zero, the result is zero
a & b // when a is zero
And why not? It would depend on the complexity of the “a” and “b”
subexpressions, of course.
The language defines "shortcutting" for operators so that you know whether "a" and "b" will both be evaluated, or just one of them. Understanding these is vital to making your code correct.
Whether the implementation /actually/ evaluates "a" and "b", and in what order, is a matter of implementation efficiency - as long as it generates results that have the correct observable behaviour.
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.