Path: csiph.com!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: you think rust may outthrone c? Date: Fri, 21 Jul 2023 02:03:51 -0700 Organization: None to speak of Lines: 49 Message-ID: <87o7k5prew.fsf@nosuchdomain.example.com> References: <5fbef78e-14f8-43c4-afaf-17fa5bad12bdn@googlegroups.com> <874jm2tbkt.fsf@nosuchdomain.example.com> <87lefeukpy.fsf@bsb.me.uk> <87edl6uf9y.fsf@bsb.me.uk> <87r0p4tyx4.fsf@bsb.me.uk> <87mszrsx6z.fsf@bsb.me.uk> <87wmyvr9kg.fsf@bsb.me.uk> <87fs5jseuv.fsf@nosuchdomain.example.com> <20230719160546.668@kylheku.com> <87bkg7s5zt.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="2370f913b850030e0527dd0f7396627d"; logging-data="3350787"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Tu2ZLRRr49NUfZCdyekWF" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:XpdgVYBizRuoRoe+yDoFBijXsfc= sha1:ewL/LCwBq20rjbDaQAp7XM3/XhA= Xref: csiph.com comp.lang.c:171025 Keith Thompson writes: [...] > The problem is that (referring to N1570, and I don't see any relevant > changes in the latest public C23 draft, N3096), Annex J says gives > > The value of an object with automatic storage duration is used > while it is indeterminate (6.2.4, 6.7.9, 6.8). > > as an example of undefined behavior. > > If that is accurate, then this program: > > #include > int main(void) { > int foo; > if (sizeof (int) == 4 && > CHAR_BIT == 8 && > INT_MAX == 2147483647 && > INT_MIN == -INT_MAX-1) > { > int bar = foo; > } > } > > has undefined behavior on an implementation where the condition is true. > (Of course that UB is likely to manifest as quietly doing nothing.) > > Annex J is non-normative, and depends on normative statements > elsewhere in the standard. Following the section numbers given in > Annex J and searching for occurrences of "indeterminate value", > I have so far been unable to confirm that the statement in Annex > J is correct. > > Either Annex J is incorrect, or accessing an uninitalized > automatic object is UB even if the object cannot possibly hold a > trap representation. (I'd be satisfied either way; I'd like the > standard to be internally consistent.) > > Perhaps someone else can find something in the standard that I've > missed. I've posted about this to comp.std.c (subject "Does reading an uninitialized object have undefined behavior?") and emailed the C23 editors. (It's likely too late to make any significant changes to C23.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */