Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Constants and undefined behavior
Date: Sat, 06 Jun 2026 18:06:37 -0700
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <86ik7v9n1e.fsf@linuxsc.com>
References: <10v7b32$2u85v$1@dont-email.me> <86ik81cfk5.fsf_-_@linuxsc.com> <10vn0bk$ghg$1@reader1.panix.com> <865x3yd21n.fsf@linuxsc.com> <10vs997$rp5$1@reader1.panix.com> <10vsnl7$lkmu$1@kst.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Sun, 07 Jun 2026 01:06:40 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2323606"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wC5k5VXX/e/0RiXtCyw/hybLAN2mwCek="; posting-host="6c1ab9963ab299b37e21cdf0811ef536"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:HEHOtv38z8AxvuoG4FGkJ3iyBis= sha1:BEDTTuKGbNaB7IL7wiw1sX/C7YU= sha256:N0erfR/P20HTro3fIlbfOIBdMYy66yABd8WI+iV409I= sha1:U2a10nnp0JptEWTz0w4Qze++pP0=
Xref: csiph.com comp.lang.c:399779
Keith Thompson writes:
> cross@spitfire.i.gajendra.net (Dan Cross) writes:
>
>> In article <865x3yd21n.fsf@linuxsc.com>,
>> Tim Rentsch wrote:
>>
>>> cross@spitfire.i.gajendra.net (Dan Cross) writes:
>>>
>>>> In article <86ik81cfk5.fsf_-_@linuxsc.com>,
>>>> Tim Rentsch wrote:
>
> [...]
>
>>>>> There's an important distinction to make here. Consider this
>>>>> program:
>>>>>
>>>>> #include
>>>>>
>>>>> int
>>>>> foo(){
>>>>> int zero = (INT_MAX+1)*0;
>>>>> return zero;
>>>>> }
>>>>>
>>>>> int
>>>>> main(){
>>>>> return 0;
>>>>> }
>>>>>
>>>>> This program does not transgress the bounds of undefined behavior.
>>>
>>> To clarify, the comments in my posting were meant to be read as
>>> saying the given text is the entire program, and that it is strictly
>>> conforming with respect to conforming hosted implementations.
>>> (Incidentally, given the rules for freestanding implementations, I'm
>>> not sure that it is even possible for any program to be strictly
>>> conforming with respect to conforming freestanding implementations.
>>> In any case my statements were meant only in the context of hosted
>>> implementations.)
[...]
> foo() has undefined behavior if it's called, so replacing its
> body with trapping code is valid.
Right.
> But (I'm reasonably sure that)
> an implementation cannot reject a program just because it can't
> prove that it has no undefined behavior during execution. [...]
Right.
>> In your example, `foo` clearly exhibits UB; I think your
>> argument is whether that has a realized effect or not, since the
>> UB is not invoked. I'm saying that in general a compiler cannot
>> possibly know that when it compiles `foo`, and is free to assume
>> the worst.
>
> foo() exhibits UB if and only if it's called during execution.
Right.