🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #1012

Re: reassociation and undefined behaviour

#1012
From: Stefan Monnier
Date: Tue, 01 Dec 2026 19:01
20 lines
1899 bytes
David Brown [2026-12-01 12:53:59] wrote:
> And in this particular case, in both C and Fortran, addition is fully
> commutative and associative for both signed and unsigned types in the
> standard language.

Is it?  AFAIK, in C

    (-2 + INTMAX) + 1

is not the same as

    -2 + (INTMAX + 1)

because the second two bumps into a UB while the first doesn't.

Of course, UB allows the compiler to choose to give the same
semantics to both forms (e.g. using wraparound).


=== Stefan
Technical Details
Message-ID: <jwvbj74bzm4.fsf-monnier+comp.arch@gnu.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11cpqih$acf5$1@dont-email.me> <86o6b6kaqf.fsf@linuxsc.com> <11ejr5e$nk8$1@reader2.panix.com> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Stefan Monnier <monnier@iro.umontreal.ca>
Newsgroups: comp.arch
Subject: Re: reassociation and undefined behaviour
Date: Tue, 01 Dec 2026 14:01:14 -0500
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <jwvbj74bzm4.fsf-monnier+comp.arch@gnu.org>
References: <11cpqih$acf5$1@dont-email.me> <86o6b6kaqf.fsf@linuxsc.com>
	<11ejr5e$nk8$1@reader2.panix.com> <11ejtoe$eoj7$1@dont-email.me>
	<11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 02 Dec 2026 00:09:31 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2490968"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18kdf0Pw0vmJJc7dvFc9PXTTwNdRpkNPuo="; posting-host="62bf958791297658d4e359aa1c748418"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:swCrw8rGZnWhsJwAQNiMCslSliM=
	sha1:YL/MkZJ2E6vk45nUUs5yknDdeCM= sha256:H9YOOEKLslfDFRpqUYbyGnCYPCiSOF/X1zozhC0+cLQ=
	sha1:R7KJBldmQsoSm8UccLD9ax7yobM= sha256:YLgEzxcAK/8k6orrtn2nWNJZK+yb1oeEjgJmBODyVPU=
In-Reply-To: <11emcgn$1k681$1@dont-email.me> (message from David Brown <david.brown@hesbynett.no> on Tue, 1 Dec 2026 12:53:59 +0100)