Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: "...the value becomes,indeterminate each time the declaration is reached"
Date: Mon, 25 Feb 2019 16:03:24 -0800
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <86pnrfct6b.fsf@mailhub.linuxsc.com>
References: <5c51d4fb.236542547@news.xmission.com> <20190201132441.0b099e5f38fdb72371bc44f0@g{oogle}mail.com> <87k1i3i8un.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="279bc562aa03f845168df75782392ca0"; logging-data="25953"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Hb6UJn00ToFMVreLzmgunykzHfFbyn6M="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:x8pYF9jHya1/6Aw5c4J1n7QCKzI= sha1:ssSEe0jsqtx7nExFo2XQzyjhQwQ=
Xref: csiph.com comp.lang.c:141379
Ben Bacarisse writes:
> Bart writes:
>
>> A local variable in C can have a scope starting halfway through a
>> block, so it cannot have a scope attached to that whole block:
>>
>> float A; // A1
>> {
>> S1;
>> S2;
>> int A; // A2
>> S3;
>> S4;
>> }
>>
>> Call those two As A1 and A2.
>
> Seems odd to do that since you are talking about names. Clearer
> to call them the float and the int.
>
>> The scope of A2 ranges from half-way through the block, to the
>> end of the block.
>
> A2 has no scope because there is no name A2. The name A is in
> scope at every line in your example. It refers to the float in
> the first 4 lines, and to the int the rest.
Your description isn't exactly in sync with how the Standard uses
the term scope, which variously applies both to names and to
entities to which the names refer. Section 6.2.1 p4 says this
(in part) about scopes and scope overlap:
If an identifier designates two different entities in the
same name space, the scopes might overlap. If so, the scope
of one entity (the inner scope) will end strictly before the
scope of the other entity (the outer scope). Within the
inner scope, the identifier designates the entity declared
in the inner scope; the entity declared in the outer scope
is hidden (and not visible) within the inner scope.