Article View: comp.lang.c++
Article #854Re: does an expression in a logical statement need parenthesis for proper evaluation?
From: Keith Thompson
Date: Fri, 13 Nov 2026 19:46
Date: Fri, 13 Nov 2026 19:46
55 lines
3604 bytes
3604 bytes
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk>
writes:
> On 13/11/2026 08:41, David Brown wrote:
[...]
>> In C, the equality and relational operators evaluate to an "int" value
>> of either 0 or 1. They never result in any other value.
>
> 0 has two representations in 1s-complement, all zeros or all ones. I am
> worried about that when using bitwise operators to implement logic in
> case a comparison yields an all-ones representation of 0. Do comparisons
> and ! always produce the all-zeros representation in 1s-complement machines?
C17 6.2.6.2p3,4:
If the implementation supports negative zeros, they shall be
generated only by:
-- the &, |, ^, ~, <<, and >> operators with operands that
produce such a value;
-- the +, - , *, /, and % operators where one operand is a negative
zero and the result is zero;
-- compound assignment operators based on the above cases.
It is unspecified whether these cases actually generate a negative
zero or a normal zero, and whether a negative zero becomes a normal
zero when stored in an object.
If the implementation does not support negative zeros, the behavior
of the &, |, ^, ~, <<, and >> operators with operands that would
produce such a value is undefined.
So the equality and comparison operators never yield a negative zero.
C23 drops this and requires 2's-complement.
You are extremely unlikely to encounter a pre-C23 C implementation that
doesn't use 2's-complement.
[...]
>> And don't bother with the "register" keyword. Optimising compilers have
>> ignored that for decades, and C++ removed it in C++17 (while preserving
>> it as a keyword for future usage).
>
> It ought to have been kept meaningful in C++ to mask operator& at least.
> I recall it was at least as early as C++98 that it was noneffective,
> definitely I know it was before C++17 because I never used C++17.
I've never had a need to disable unary &. Have you?
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID:
<11d7pe4$1b62o$1@kst.eternal-september.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mailReferences:
<11cj4a0$23796$1@dont-email.me> <11cj8ch$24f93$1@dont-email.me> <11cj9he$24mi0$1@dont-email.me> <11d54u2$863c$1@dont-email.me> <11d5eg2$bfhu$1@dont-email.me> <11d6if2$lqnd$1@dont-email.me> <11d7a99$th7r$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: does an expression in a logical statement need parenthesis for proper evaluation? Date: Fri, 13 Nov 2026 11:46:09 -0800 Organization: None to speak of Lines: 55 Message-ID: <11d7pe4$1b62o$1@kst.eternal-september.org> References: <11cj4a0$23796$1@dont-email.me> <11cj8ch$24f93$1@dont-email.me> <11cj9he$24mi0$1@dont-email.me> <11d54u2$863c$1@dont-email.me> <11d5eg2$bfhu$1@dont-email.me> <11d6if2$lqnd$1@dont-email.me> <11d7a99$th7r$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 13 Nov 2026 19:46:12 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="1415256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dt2pCy/yTDTUaWBWcYfQg"; posting-host="aa5ecddc38785e47bf3ec797676124f1" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:uySBX5doFcTwAy1lOm3ouhf+h2k= sha256:CHrswECkH48FK8VtUDueHELliZ6p9DFf6LMxfpo9xEA= sha1:CMDzrOA+sXLzjIJxtcXNnlgWwvU= sha256:R/ZOHiqZK3s3Hhx/Q4zYobYArzxaoFyLVp/BONu+BGs=