Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Safety of casting from 'long' to 'int'
Date: Tue, 12 May 2026 18:36:43 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <867bp8m6ok.fsf@linuxsc.com>
References: <10su8cn$am9i$1@dont-email.me> <10thu77$1v1r3$2@dont-email.me> <10ti57c$2234d$1@dont-email.me> <10tigio$1l93l$2@dont-email.me> <10tj2hk$bbf$1@reader1.panix.com> <10tk4sg$2l19a$2@dont-email.me> <10tk94h$2oc5t$1@kst.eternal-september.org> <10tkep4$2pv64$1@dont-email.me> <10tr80l$odia$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 13 May 2026 01:36:43 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2494327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18P/Y3vDhhM8zSmNBTIaktSgmcp1ZhZt38="; posting-host="ace8b6eaa328dcf44f89a3207699c4cb"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:LDz6R/EyNLXUWXeMJcVtoUjrDlc= sha1:ETwY25/CIPRrsNyli8F4XLbqOjg= sha256:cjNpFh0vnHXPXO9msCe+3OI5gdRJX/s1745HrkmGnnI= sha1:aJoNQRu9GoSTwXUxcQJelbxYdqc=
Xref: csiph.com comp.lang.c:398837
James Kuyper writes:
> On 2026-05-08 06:43, David Brown wrote:
> ...
>
>> Yes, I have heard that argument before. I am unconvinced that the
>> "value preserving" choice actually has any real advantages. I also
>> think it is a misnomer - it implies that "unsigned preserving" would
>> not preserve values, which is wrong.
>
> Unsigned-preserving rules would convert a signed value which might be
> negative to unsigned type more frequently than the value preserving
> rules do.
This statement is wrong. An "unsigned preserving" promotion rule
converts a signed value to a signed value and an unsigned value to
an unsigned value. The value being converted stays the same in both
cases. Both an "unsigned preserving" promotion and a so-called
"value preserving" promotion preserve the value of the operand being
promoted (and converted).