Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Scope of identifiers Date: Tue, 13 Jun 2017 12:16:17 -0700 Organization: None to speak of Lines: 44 Message-ID: References: <081872d4-3f9d-0004-8c0d-25a274bba7bb@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="3c5458cd01e27031549862a8458a90ae"; logging-data="3072"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T2Eug9RuvkyF37YRh/8qC" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:LdJdE5MMfdjgkQFugobKkh7Wlag= sha1:jKuovUOqAcik9A0XxANHA4w9GsU= Xref: csiph.com comp.lang.c:112127 David Kleinecke writes: > On Monday, June 12, 2017 at 1:19:09 PM UTC-7, Keith Thompson wrote: [...] >> What I proposed was to replace the current definition of "same scope" >> (which is problematic because two non-identical scopes can be the "same >> scope") by something like "matching scope". (I'm open to a better >> adjective than "matching".) I think that solves the (minor) problem of >> "same scope" being confusing, it doesn't add to the number of defined >> terms, and it's a fairly minimal change. > > If one looks at the case of block scope and the old C approach > one observes that all the declarations come before the statements. > If one thinks of "starting" a scope extends through all the > declarations then a single concept of "scope" holds. > > This observation doesn't help the present day situation but it does > help explain how the situation cam about. Given: { int a = 10; int b = a; int c = d; /* illegal */ int d = 20; /* statements ... */ } the initialization of c is invalid because the scope of d doesn't start until the line on which it's defined. The lifetimes of all 4 objects begin at the same time, when execution reaches the opening "{", but their scopes begin at 4 different locations. All 4 scopes are the "same scope" as the standard defines that phrase. (Scope is a compile-time concept; lifetime is a run-time concept.) [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"