Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "...the value becomes,indeterminate each time the declaration is reached" Date: Tue, 29 Jan 2019 16:36:41 -0800 Organization: None to speak of Lines: 46 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="b08549a0708368ce183a470765040d39"; logging-data="24969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jWEQSQiY4Ln91UEKPJq5T" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:FfqVNb6NHlBDmk9eWNoi/fqaLO4= sha1:RSCAe8GA/QoeljIPhlVXTSpM4+E= Xref: csiph.com comp.lang.c:140402 Andrey Tarasevich writes: > On 1/29/2019 11:30 AM, David Brown wrote: >> Why would you want i to keep its value?  If you choose to write >> spaghetti code and jump around like this, the compiler is free to do >> whatever it likes with the value of "i" the second time around >> (including keeping the value). > > The question is "why?". The code "jumps around" well within the lifetime > of the object in question. Why is the object not guaranteed to keep its > value at that specific spot of its lifetime? What is the reason this > potential possibility for loss of value was introduced in C99? It wasn't > there in C89/90 (unless it was a defect, of course). Here's one possible rationale. An uninitialized local object has an indeterminate value until a value has been assigned to it. { int x; int y = 42; } A compiler could treat `int x;` as `int x = SOME_WEIRD_VALUE;` to aid in debugging. It might store some consistent bit pattern that's unlikely to appear accidentally. (I think I've seen a repeating 0xe5 pattern used this way). { int x /* = (int)0xe5e5e5e5 */; int y = 42; } If you write code that uses a goto to transfer control to a point within the lifetime of x but before its declaration (yes, my wording is a little sloppy), it would not be reasonable to require such a compiler to treat this as a special case and omit the initialization when the declaration is reached a second time. I don't know whether the authors of the standard had this kind of scenario in mind. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */