Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: David Brown Newsgroups: comp.compilers Subject: Re: Optimization techniques Date: Tue, 7 May 2019 16:43:42 +0200 Organization: A noiseless patient Spider Lines: 39 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <19-05-054@comp.compilers> References: <72d208c9-169f-155c-5e73-9ca74f78e390@gkc.org.uk> <19-04-020@comp.compilers> <19-04-025@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="27511"; mail-complaints-to="abuse@iecc.com" Keywords: C, standards Posted-Date: 07 May 2019 18:47:56 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Content-Language: en-GB Xref: csiph.com comp.compilers:2289 On 26/04/2019 10:33, alexfrunews@gmail.com wrote: > On Thursday, April 25, 2019 at 1:14:54 PM UTC-7, Martin Ward wrote: > ... >> With the current situation, anyone wanting to avoid >> undefined behaviour (and don't we all?) has to write code like >> this for any signed operation: >> >> signed int sum; >> if (((si_b > 0) && (si_a > (INT_MAX - si_b))) || >> ((si_b < 0) && (si_a < (INT_MIN - si_b)))) { >> /* Handle error */ >> } else { >> sum = si_a + si_b; >> } > > In this day and age it is a shame that the language that is still very > much alive does not provide the programmer with easy-to-use (and > implement!) tools to perform/handle: > > - overflow checks like the above for +, -, *, /, > %, <<, both signed and unsigned > - mathematically meaningful comparison of signed > and unsigned integers > - arithmetic right shift out of the box > - ditto rotation > - arbitrary precision arithmetic (for integers > of compile-time-constant length) > - endianness at last > - (I probably forget many more) > One possible consideration here is that C, these days, regularly means gcc and/or clang. These dominate the C compiler market to a very large extent. And they both have support for overflow checks (and wrapping signed arithmetic, if you want). Some other compilers I have used have copied extensions from gcc. Still, a major point of C is that it does not change much - it is intentionally kept (relatively) small and as stable as possible.