Re: Undefined Behavior Optimizations in C

Keith Thompson <Keith.S.Thompson+u@gmail.com>
Fri, 20 Jan 2023 13:54:36 -0800

          From comp.compilers

Related articles
[23 earlier articles]
Re: Undefined Behavior Optimizations in C spibou@gmail.com (Spiros Bousbouras) (2023-01-18)
Re: Undefined Behavior Optimizations in C david.brown@hesbynett.no (David Brown) (2023-01-18)
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-18)
Re: Undefined Behavior Optimizations in C alexfrunews@gmail.com (Alexei A. Frounze) (2023-01-19)
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-20)
Re: Undefined Behavior Optimizations in C tkoenig@netcologne.de (Thomas Koenig) (2023-01-20)
Re: Undefined Behavior Optimizations in C Keith.S.Thompson+u@gmail.com (Keith Thompson) (2023-01-20)
Re: Undefined Behavior Optimizations in C anton@mips.complang.tuwien.ac.at (2023-01-21)
Re: Undefined Behavior Optimizations in C 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-22)
Re: Undefined Behavior Optimizations in C anton@mips.complang.tuwien.ac.at (2023-01-22)
Re: Undefined Behavior Optimizations in C martin@gkc.org.uk (Martin Ward) (2023-01-23)
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-23)
Re: Undefined Behavior Optimizations in C dave_thompson_2@comcast.net (2023-01-28)
| List of all articles for this month |

From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.compilers
Date: Fri, 20 Jan 2023 13:54:36 -0800
Organization: None to speak of
References: 23-01-027 <sympa.1673343321.1624.383@lists.iecc.com> 23-01-031 23-01-041 23-01-062 23-01-063 23-01-066
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="25720"; mail-complaints-to="abuse@iecc.com"
Keywords: C, arithmetic
Posted-Date: 20 Jan 2023 22:09:05 EST

gah4 <gah4@u.washington.edu> writes:
[snip]
> For many years, C allowed for sign-magnitude and ones' complement
> representation.


It still does. The upcoming 2023 ISO C standard mandates 2's-complement
for signed integer types, but it hasn't been published yet.


[...]


> Now, C has unsigned int which you can use when you need specific
> overflow behavior (except on some Unisys machines).


If a Unisys C implementation doesn't behave as the standard requires
with respect to unsigned overflow, then it's a non-conforming
implementation. (Non-conforming implementations can still be useful.)


[...]


> As C allows for both UB and system-dependent behavior, and it is
> hard for people to remember every case of each one, it is unreasonable
> to me, to assume fixed point overflow is UB.


C has:
- Undefined behavior (the standard imposes no requirements);
- Unspecified behavior (the standard provides 2 or more possibilities
    and implementations can choose arbitrarily; an example is the order of
    evaluation of function arguments); and
- Implementation-defined behavior (unspecified behavior where the
    implementation must document its choice).


Signed integer overflow has undefined behavior -- not because it is or
isn't reasonable, but because the standard says so.


Even in C23, the mandate for 2's-complement representation doesn't
imply a requirement for 2's-complement behavior on overflow.


[...]


--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.