Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Which side of bitwise OR is evaluated first?
Date: Wed, 14 Apr 2021 07:54:51 -0700
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <86a6q0j4qs.fsf@linuxsc.com>
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="e14ed2c9513d4c03c630dd7e5aa045d1"; logging-data="9419"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VNljmXF/bjV8UeWFj8SLQ/YVwsPwAVU0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:tTOxdJlGpvXGheHukUnw5MANhew= sha1:quG+D4dvwDWhwB/94C0eN5GFKLc=
Xref: csiph.com comp.lang.c:160096
Richard Damon writes:
> C does NOT provide any promise as to the order of evaluation for most
> operators.
>
> || and && and , are the exceptions that come to mind that explicitly
> will evaluate the first and then the second, and for || and && the
> second is only evaluated if its value is needed, so for || only if the
> first value was 'false', and for && only if the first value was 'true'
Of course the one other case is the ?: operator, which always
evalutes the first operand first, completely, and then evaluates
either the second or third operand after that.
(C++ has a bunch of other cases, on which I'm not completely
sure of which ones or when they came into effect exactly.)