“Undefined behavior” considered harmful (was Re: Bug 29863 - Segmentation fault in memcmp-sse2.S…)

Florian Weimer fw@deneb.enyo.de
Fri Dec 30 13:28:07 GMT 2022


* Andreas Schwab:

> On Dez 29 2022, Zack Weinberg via Libc-alpha wrote:
>
>> 1. The C standard uses “undefined behavior” far more liberally than it
>>    ought to.  In many cases of existing UB the committee could define
>>    the behavior (possibly as implementation-defined or unspecified)
>>    without any actual negative consequences.  It seems the committee
>>    *is* moving in this direction as of C2x, for instance by dropping
>>    the allowances for non-twos-complement signed arithmetic, but they
>>    could and should go a lot farther down that road.
>
> That's not removing an undefined behavior, it's removing an
> implementation choice.

Right, arithmetic is still not twos-complement, it's only about
representation.  Same with C++.

(I associate twos-complement signed *arithmetic* with the obvious
(unsigned) overflow behavior.)


More information about the Libc-alpha mailing list