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: UB or not UB? was: On Undefined Behavior
Date: Tue, 03 Feb 2026 21:53:49 -0800
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <86ecn1hx5e.fsf@linuxsc.com>
References: <10j6qdt$3q9n4$1@dont-email.me> <20260112162857.00003dd8@yahoo.com> <10k360j$2epre$1@dont-email.me> <20260112193652.000051d0@yahoo.com> <86qzrulht3.fsf@linuxsc.com> <20260112224107.000071b1@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 04 Feb 2026 05:53:59 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="30e2bd46efc1ceede85686db5fb0dc7e"; logging-data="2214876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MeW7Ivd+uPCBBTjcY87MJ7CifeHaVEgU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:TX7H5w5BjtX2jTMd/vt4vdrfh+E= sha1:k3y6aahwYA7IrYUukB7S1JOFXSE=
Xref: csiph.com comp.lang.c:396585
Michael S writes:
> On Mon, 12 Jan 2026 12:03:36 -0800
> Tim Rentsch wrote:
>
>> Michael S writes:
>>
>>> On Mon, 12 Jan 2026 08:03:31 -0800
>>> Andrey Tarasevich wrote:
>>>
>>>> On Mon 1/12/2026 6:28 AM, Michael S wrote:
>>>>
>>>>> According to C Standard, access to p->table[4] in foo1() is UB.
>>>>> ...
>>>>> Now the question.
>>>>> What The Standard says about foo2() ? Is there UB in foo2() as
>>>>> well?
>>>>
>>>> Yes, in the same sense as in `foo1`.
>>>>
>>>>> gcc code generator does not think so.
>>>>
>>>> It definitely does.
>>
>> Right.
>
> May be. But it's not expressed by gcc code generator or by any
> wranings. So, how can we know?
I know the behavior is undefined by what is said in the C standard.
For what gcc developers think of the question, for me the totality
of circumstantial evidence suffices. I have nothing to offer if the
goal is to convince skeptics.
>>> Do you have citation from the Standard?
>>
>> The short answer is section 6.5.6 paragraph 8.
>
> I am reading N3220 draft
> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
> Here section 6.5.6 has no paragraph 8 :(
I hope it isn't too much to expect that if N3220 doesn't have
what you are looking for then you would try looking in earlier
versions of the C standard, either C99 (N1256) or C11 (N1570).
>> There is amplification in Annex J.2, roughly three pages
>> after the start of J.2. You can search for "an array
>> subscript is out of range", where there is a clarifying
>> example.
>
> I see the following text:
> "An array subscript is out of range, even if an object is apparently
> accessible with the given subscript (as in the lvalue expression
> a[1][7] given the declaration int a[4][5]) (6.5.7)."
>
> That's what you had in mind?
Yes.
Note the section quoted section number, 6.5.7, gives the correct
section number in N3220 to locate the aforementioned reference.
I see that in N3220 the relevant paragraph is paragraph 9 rather
than paragraph 8. I hope that would be evident by looking at the
contents of section 6.5.7.