Re: Shortcut Booleans

Liste des GroupesRevenir à cl c  
Sujet : Re: Shortcut Booleans
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 09. Jun 2024, 13: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.

Date Sujet#  Auteur
7 Jun 24 * Shortcut Booleans6Lawrence D'Oliveiro
7 Jun 24 `* Re: Shortcut Booleans5bart
8 Jun 24  `* Re: Shortcut Booleans4Lawrence D'Oliveiro
9 Jun 24   `* Re: Shortcut Booleans3David Brown
10 Jun 24    `* Re: Shortcut Booleans2Lawrence D'Oliveiro
10 Jun 24     `- Re: Shortcut Booleans1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal