Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #143055
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Scopes of identifiers |
| Date | 2019-04-11 20:19 -0700 |
| Organization | None to speak of |
| Message-ID | <lnpnpr29mg.fsf@kst-u.example.com> (permalink) |
| References | (1 earlier) <q8o4h9$dqe$1@dont-email.me> <5b59a4e9-81d3-4442-a9e6-6fa8419a08e7@googlegroups.com> <q8odkv$60b$1@dont-email.me> <lny34g13xb.fsf@kst-u.example.com> <q8oqkc$ujb$1@dont-email.me> |
Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
> On 4/11/2019 5:08 PM, Keith Thompson wrote:
>>> No. Nested blocks mean nested scopes in C. It does not matter whether
>>> the block is "explicit" (a pair of `{}`) or "implicit" (as described
>>> above). This immediately means that scopes associated with nested blocks
>>> have different termination points.
>>
>> What are these two different termination points?
>
> The end of the "explicit" block and the end of the "implicit" block.
There's nothing implicit about either block. One block is the
iteration statement. The other is the statement (a compound
statement) that is the loop body. My best guess is that by
"implicit" you mean a block that's not delimited by opening and
closing curly braces, but nothing in the standard says that a block
is delimited by braces, or that a block that's not delimited by
braces is "implicit".
(In C90, "block" was synonymous with "compound statement", but
that was changed in C99.)
>> Here's the code again:
>>
>> for (int i = 0; i < 10; ++i)
>> {
>> int i = 42;
>> }
>>
>> There are two blocks here, one for the for statement and one for its
>> body. N1570 6.8.5p5:
>>
>> An iteration statement is a block whose scope is a strict
>> subset of the scope of its enclosing block. The loop body is
>> also a block whose scope is a strict subset of the scope of
>> the iteration statement.
>
> Exactly. The word *strict* is used in this text to emphasize the fact
> that these blocks are nested, to emphasize the fact that they are different.
I think that's a stretch.
In the case of scopes, if the phrase "strict subset" is intended to
imply that the two scopes do not end at the same point, that's a poor
way to express that intent.
A scope is by definition a "region of program text" (6.2.1p2). Do you
claim that the termination point of a scope is something other than the
end of that region of program text?
>> One scope starts at the "for" keyword and ends at the "}" symbol.
>> The other scope starts at the "{" symbol and ends at the "}" symbol.
>> They start at different points, but they terminate at the same point.
>
> No, they don't. For some reason you are attempting to attach beginning
> and termination points of blocks to some physical characters in the
> source code.
Yes, of course I am. How else would you define them? Blocks are
syntactic constructs consisting of sequences of tokens. Both of these
blocks have the same last token.
> The language defines no such attachment. Beginning and
> termination points are concepts. And two different blocks always have
> two different termination points. Pretty simple.
Proof by blatant assertion? Can you explain what a "termination point"
is other than by calling it a "concept"?
> One might claim that the document is underdefined, but to me it looks
> like a stretch. The intent is perfectly clear: introduce some extra
> ("implicit") blocks that envelop the existing blocks. These extra blocks
> are "invisible" but otherwise behave just like normal enveloping block do.
>
> I don't see why anyone would interpret this wording an attempt to
> introduce into the language something as bizarre and foreign as
> "two-headed" blocks: blocks that begin at different points but terminate
> at the same one. Why? This is just... completely unnecessary in C.
I interpret it that way because that's what it says.
The definition of "same scope" goes back to C89/C90, and it worked fine
then. It was intended to cover things like this:
/* Example 1 */
{
int i = 10;
int i = 20; /* invalid, "same scope" */
}
When C99 added new kinds of blocks, and thus new rules for scopes, the
definition wasn't updated. It seems clear to me that something like:
/* Example 2 */
for (int i = 0; i < 10; ++i) {
int i; /* Does this have the "same scope"? */
}
is *intended* to be valid (as the authors of gcc, clang, and tcc appear
to have assumed), but the definition of "same scope" was not updated to
handle cases like this.
In Example 1 above both "i"s have the same innermost enclosing block,
and in Example 2 the two "i"s have different innermost enclosing blocks.
I think the definition of "same scope" needs to be updated to reflect
that (while still covering non-block scopes).
And a phrase other than "same scope" would be clearer -- perhaps
"colliding scopes"?
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-10 16:15 -0700
Re: Scopes of identifiers Bart <bc@freeuk.com> - 2019-04-11 00:33 +0100
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-10 16:45 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-10 18:31 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-10 16:34 -0700
Re: Scopes of identifiers Robert Wessel <robertwessel2@yahoo.com> - 2019-04-10 20:50 -0500
Re: Scopes of identifiers James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-10 20:02 -0700
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-10 20:58 -0700
Re: Scopes of identifiers luser droog <luser.droog@gmail.com> - 2019-04-10 21:48 -0700
Re: Scopes of identifiers Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-04-11 11:57 -0700
Re: Scopes of identifiers scott@slp53.sl.home (Scott Lurndal) - 2019-04-11 19:12 +0000
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-11 12:35 -0700
Re: Scopes of identifiers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-12 01:11 +0100
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-12 05:29 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-12 05:39 -0700
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-11 14:00 -0700
Re: Scopes of identifiers Nick Bowler <nbowler@draconx.ca> - 2019-04-15 19:48 +0000
Re: Scopes of identifiers Bart <bc@freeuk.com> - 2019-04-11 10:36 +0100
Re: Scopes of identifiers Bart <bc@freeuk.com> - 2019-04-11 14:25 +0100
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-11 10:20 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-11 05:00 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-11 06:42 -0700
Re: Scopes of identifiers James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-11 08:11 -0700
Re: Scopes of identifiers BGB <cr88192@gmail.com> - 2019-04-10 22:35 -0500
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-10 22:04 -0700
Re: Scopes of identifiers BGB <cr88192@gmail.com> - 2019-04-11 05:46 -0500
Re: Scopes of identifiers John Bode <jfbode1029@gmail.com> - 2019-04-11 12:04 -0700
Re: Scopes of identifiers James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-11 13:18 -0700
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-11 14:31 -0700
Re: Scopes of identifiers Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-04-11 12:28 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-11 12:50 -0700
Re: Scopes of identifiers James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-11 14:20 -0700
Re: Scopes of identifiers Thiago Adams <thiago.adams@gmail.com> - 2019-04-11 14:43 -0700
Re: Scopes of identifiers Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-04-11 15:04 -0700
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-11 17:08 -0700
Re: Scopes of identifiers Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-04-11 18:45 -0700
Re: Scopes of identifiers James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-11 23:16 -0400
Re: Scopes of identifiers Keith Thompson <kst-u@mib.org> - 2019-04-11 20:19 -0700
Re: Scopes of identifiers Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-12 14:39 -0700
Re: Scopes of identifiers Ike Naar <ike@sdf.lonestar.org> - 2019-04-13 20:02 +0000
Re: Scopes of identifiers James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-11 23:26 -0400
csiph-web