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: Sun, 03 May 2026 20:27:36 -0700 Organization: A noiseless patient Spider Lines: 20 Message-ID: <86jytjyhuf.fsf@linuxsc.com> References: <10su8cn$am9i$1@dont-email.me> <10sv4v0$h9mn$1@dont-email.me> <84c1c180f4d5b96259a631bdb09b6054b4eb44d2.camel@gmail.com> <10svgfv$l2bu$1@dont-email.me> <10t4hse$22u36$1@dont-email.me> <97a1c40bf71cfe8edab25d5ac8a1ad435c3995e5.camel@gmail.com> <10t4tjd$25vb5$1@dont-email.me> <10t4viv$25van$2@dont-email.me> <10t5dn8$2aje4$1@dont-email.me> <10t5ip1$2crol$2@dont-email.me> <10t5v4p$2g7lq$1@dont-email.me> <10t60sp$2gp96$2@dont-email.me> <25fd121d7cbe895b0f9de5f9176fa2e6f423c85c.camel@gmail.com> <10t8429$33csl$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 04 May 2026 03:27:37 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3548936"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aqqUimGB8KrIta4FohpbJSl3piXk8hBA="; posting-host="a1e35ddd35ce451998c695505411656f" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:NDC57wkOsqjXolnqk0zbuxhCGlU= sha1:eHR88xIK4tL2E1P93K0AnYFTKSk= sha256:lDJVZns6IT8onyyOkB0N2vmnT8bYG9RZqUzDOAdw3Gw= sha1:G/0Pt4dePD9oRI8WheUK/JRbvNE= Xref: csiph.com comp.lang.c:398271 James Kuyper writes: [...] > When you write code with Undefined behavior, that means the standard > imposes no restrictions on the behavior, so you are in effect asking > the compiler to do whatever it wants to do - you are explicitly > saying that you don't care what it does. [...] Assuming the use of a construction with undefined behavior was intentional, I would say this statement is at least incomplete. It could be that the UB invoker is saying, in effect, "I know that other compilers might do the wrong thing here, but I also know that the compiler being used for this project will do what is wanted." That might be because of a defined extension; or because the behavior desired is verified in some way; or perhaps some other reason. In any case certainly it is possible that the choice was made not because of lack of caring but because some awareness of the particular circumstances allows more confidence in what will happen than "undefined behavior" generally provides.