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: Mon, 12 Jan 2026 12:03:36 -0800 Organization: A noiseless patient Spider Lines: 29 Message-ID: <86qzrulht3.fsf@linuxsc.com> References: <10j6qdt$3q9n4$1@dont-email.me> <20260112162857.00003dd8@yahoo.com> <10k360j$2epre$1@dont-email.me> <20260112193652.000051d0@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 12 Jan 2026 20:03:41 +0000 (UTC) Injection-Info: dont-email.me; posting-host="9b2aefc29b3134bf9032a72ed7f58944"; logging-data="2738249"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AvOKGJ1bt7ul7IKMxFk7omfzJZZLSmPc=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:CMYVpuRIQD9/Yn0lYKeK6vEy0gI= sha1:v6eCbuvYPLpNMc9IDn8RpjF5FMg= Xref: csiph.com comp.lang.c:396379 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. > Do you have citation from the Standard? The short answer is section 6.5.6 paragraph 8. 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.