Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How to avoid an overflow during multiplication? Date: Fri, 31 Dec 2021 11:38:01 -0800 Organization: None to speak of Lines: 28 Message-ID: <877dbk36qu.fsf@nosuchdomain.example.com> References: <8735m954yz.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="535866f7e1f9aa1f9c859c38fe4fa9a9"; logging-data="30610"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XHiF1fJFqHIxohqXt5ibp" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:DBpeHPASlO2uzKyY1EpZVplwaik= sha1:u/GW9JhN1BTn+ZdW3ZYP57RUpEk= Xref: csiph.com comp.lang.c:164170 Mateusz Viste writes: > 2021-12-31 at 13:41 GMT, Stefan Ram wrote: >> |A computation involving unsigned operands can never overflow, >> |because a result that cannot be represented by the resulting >> |unsigned integer type is reduced modulo the number that is >> |one greater than the largest value that can be represented by >> |the resulting type. >> n2310, 6.2.5p9 > > Had missed that one, thanks! > > (In my ANSI C copy it is at 6.1.2.5, p23) You mean ISO C. (C standards have been published by ISO, not ANSI, since 1990.) Which edition are you using? It's section 6.2.5 in C99 and later. If you're seeing that paragraph in section 6.1.2.5, you're probably using the C90 standard (which doesn't have paragraph numbers, BTW). I suggest grabbing a more recent draft. N1570 is nearly equivalent to the C11 standard. (There are drafts that are close to the C17 standard, but most of them are password protected.) http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */