| Deutsch English Français Italiano |
|
<v4441g$3f1d5$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: Shortcut Booleans Date: Sun, 9 Jun 2024 13:35:12 +0200 Organization: A noiseless patient Spider Lines: 22 Message-ID: <v4441g$3f1d5$2@dont-email.me> References: <v3uoq3$21g4g$7@dont-email.me> <v3uv51$22afr$2@dont-email.me> <v40ge7$2edfj$3@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 09 Jun 2024 13:35:12 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1062c5425b43bc2e4c38108051e56be8"; logging-data="3638693"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ryAGBgqcZvDbC4RFavly0bJaxqVSExmg=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:kmEU9KRdX/LhOLCmWtPFWuXUHUc= Content-Language: en-GB In-Reply-To: <v40ge7$2edfj$3@dont-email.me> Bytes: 2055 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.