Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: UB in asm Date: Thu, 28 Dec 2017 09:25:15 -0800 Organization: None to speak of Lines: 26 Message-ID: References: <5iZ%B.40934$zw5.23692@fx17.iad> <7L60C.121075$fm1.52991@fx17.am4> <8c32b95e-7cd6-403d-bde7-d53dcd02e2cc@googlegroups.com> <8581d213-699c-29f0-7ada-32f5509d8e28@verizon.net> <0YO0C.200936$rE1.115426@fx14.am4> <87bmiic4bt.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="496916c69df479f182ddc69e08fa652d"; logging-data="4019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19N679NCZKgkVGgZ9p1WI2h" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:WZFozykmbg3hvgWlFsqcyqgYnFs= sha1:CnK2Dfk7qUo4EDEwjOiLjwx5fg4= Xref: csiph.com comp.lang.c:124843 Richard Damon writes: > On 12/28/17 11:46 AM, David Brown wrote: >> Or use: >> >> a = (uint32_t) a + 1u; >> >> for code that is simpler, and portable to all practical systems (that >> support int32_t). > > The one problem with this is that the conversion of an unsigned number > greater that INT_MAX to a signed integer still invokes undefined > behavior, so an aggressively optimizing compiler might still assume that > a can't equal INT_MIN. No, such a conversion yields an implementation-defined result (or raises an implementation-defined signal). Raising an implementation-defined signal could, I suppose, lead to undefined behavior, but I don't know of any compiler that takes advantage of that permission (added in C99 IIRC). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"