Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #112196
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Scope of identifiers |
| Date | 2017-06-14 09:19 -0700 |
| Organization | None to speak of |
| Message-ID | <lnd1a6ee4d.fsf@kst-u.example.com> (permalink) |
| References | (5 earlier) <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> <e60a5ee2-13c8-4326-b9e6-9055bdd69b25@googlegroups.com> |
supercat@casperkitty.com writes:
> On Tuesday, June 13, 2017 at 11:02:59 PM UTC-5, David Kleinecke wrote:
>> 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.
>
> Under C89, a single-pass implementation given:
>
> int x = expressionYieldingLotsOfCode;
> int y;
>
> could generate code:
>
> bump stack pointer to leave space for x
> evaluate expresstionYieldingLotsOfCode
> bump stack pointer to leave space for y
>
> The compiler wouldn't need to know about y, or much space it would take,
> when generating code for the big expression. Under C99, however, a
> compiler has to handle:
>
> someLabel:
> arbitraryStatement;
> int x = expressionYieldingLotsOfCode;
> int y;
>
> If jumping before a declaration would end a variable's lifetime, an
> implementation could simply precede the jump with code that would reset
> the stack pointer to the value it had the first time it ran the
> arbitrary statement. Under C99 rules, however, space would need to
> remain reserved for y the second time the code runs.
Under C90, as under C99, the lifetime of an object with automatic
storage duration begins on entry to the enclosing block.
A C90 compiler could defer allocation until control reaches the
declaration, but that's an optimization, not part of the visible
semantics. A C99 compiler can perform exactly the same optimization
if there are no labels preceding the declaration.
--
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