Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #112195
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: Scope of identifiers |
| Date | Wed, 14 Jun 2017 09:12:13 -0700 |
| Organization | None to speak of |
| Lines | 71 |
| Message-ID | <lnh8zieeg2.fsf@kst-u.example.com> (permalink) |
| References | <ohmea9$nft$1@gioia.aioe.org> <lnink1gnzy.fsf@kst-u.example.com> <081872d4-3f9d-0004-8c0d-25a274bba7bb@verizon.net> <ln60g1gfmy.fsf@kst-u.example.com> <e74c416a-d6e4-7f4d-e939-ec5f0cfd010b@verizon.net> <lnwp8hez7v.fsf@kst-u.example.com> <eb8fd32a-b3d5-4767-8a78-3d85ade2fc92@googlegroups.com> <ln60fzg0la.fsf@kst-u.example.com> <e3512b0c-6925-4ef8-ae8b-f142f2de4fc3@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx02.eternal-september.org; posting-host="96bbf95725af2559ab0735ee54475e20"; logging-data="28600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gswl6AbnklcDqh6OZcMfj" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:oiJZfiADLd5Jke6rsjnr2QYrRXI= sha1:nuqOC+dCH5dju2q31xPN/x6f8iU= |
| Xref | csiph.com comp.lang.c:112195 |
Show key headers only | View raw
David Kleinecke <dkleinecke@gmail.com> writes:
> On Tuesday, June 13, 2017 at 12:16:26 PM UTC-7, Keith Thompson wrote:
>> David Kleinecke <dkleinecke@gmail.com> writes:
[...]
>> > 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.)
>>
>> [...]
>
> OK if you want to get pedantic.
What's pedantic about it? You suggested
If one thinks of "starting" a scope extends through all the
declarations then a single concept of "scope" holds.
i.e., that the scope begins at the top of the block. That's simply
incorrect.
> In the sense of the statements -
> all the declarations happen first. They generally are such that
> they can be freely shuffled around.
As I demonstrated, they clearly can't if some declarations depend on
other declarations.
> C has taken advantage of the
> fact that they have to be declared in some order to introduce
> more flexibility. It can be argued that initialization is a bad
> idea and should be avoided and if there are no initializations
> the declarations can be made in any order.
Fortunately, I've never heard anyone argue that "initialization is
a bad idea and should be avoided".
> In other words in a primitive pre-C there was no initialization
> and the declarations could be thought of as simultaneous and all
> the scopes as the same. This simplicity is lost when initialization
> was introduced.
I don't believe we were talking about "primitive pre-C".
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Scope of identifiers Steve Keller <keller@no.invalid> - 2017-06-12 18:08 +0200
Re: Scope of identifiers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-12 12:22 -0400
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-12 09:39 -0700
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-12 09:38 -0700
Re: Scope of identifiers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-12 14:41 -0400
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-12 12:39 -0700
Re: Scope of identifiers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-12 15:53 -0400
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-12 13:19 -0700
Re: Scope of identifiers David Kleinecke <dkleinecke@gmail.com> - 2017-06-13 11:01 -0700
Re: Scope of identifiers jameskuyper@verizon.net - 2017-06-13 11:25 -0700
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-13 12:16 -0700
Re: Scope of identifiers David Kleinecke <dkleinecke@gmail.com> - 2017-06-13 21:02 -0700
Re: Scope of identifiers Ian Collins <ian-news@hotmail.com> - 2017-06-14 21:53 +1200
Re: Scope of identifiers supercat@casperkitty.com - 2017-06-14 08:10 -0700
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-14 09:19 -0700
Re: Scope of identifiers supercat@casperkitty.com - 2017-06-14 10:14 -0700
Re: Scope of identifiers Keith Thompson <kst-u@mib.org> - 2017-06-14 09:12 -0700
Re: Scope of identifiers Robert Wessel <robertwessel2@yahoo.com> - 2017-06-12 13:02 -0500
csiph-web