Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #112075

Re: Scope of identifiers

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Scope of identifiers
Date 2017-06-12 12:39 -0700
Organization None to speak of
Message-ID <ln60g1gfmy.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>

Show all headers | View raw


"James R. Kuyper" <jameskuyper@verizon.net> writes:
> On 06/12/2017 12:38 PM, Keith Thompson wrote:
>> Steve Keller <keller@no.invalid> writes:
>>> While reading again in the standard about declarations and (tentative)
>>> definitions, and linkage, I also read about scope of identifiers and
>>> was confused:
>>>
>>> The standard says in 6.2.1p6 that "two identifiers have the same
>>> scope if and only if their scopes terminate at the same point."
>>
>> Yes, and the phrase "same scope" is in italics, which means this is the
>> definition of the term.  Two identifiers can have the *same scope*
>> even if their scopes begin in different places.
>>
>> It might have been less confusing if the standard had used a different
>> phrase, perhaps "matching scope".
>
> I think the fundamental problem is at a slightly higher level. They had 
> two concepts of scope, and tried to use the same name for both concepts. 
> I think it would have been easier to describe things clearly if they had 
> used two different terms for the two concepts. I'll use "visibility 
> range" for one of the two, and "scope" for the other. Everything below 
> is my suggestion how the standard could be re-written for clarity on 
> this issue (it certainly does NOT describe what the standard currently 
> says). My intent is to leave the actual meaning of the standard's words 
> unchanged: if my suggestion fails to do that, it is my re-wording that 
> is at fault.
>
> Suggested conceptual reorganization:

Summary: For a declaration in a block, an identifiers "visibility range"
is the same as what the standard currently calls its "scope", and
extends from the declaration to the end of the block.  Its "scope" (new
meaning) extends from the beginning of the block to the end of the
block.  (Glossing over, for now, what these terms mean for scopes other
than block scope.)

I haven't checked, but I can't think of anything in the standard that
refers to your new wider "scope" other than the definition of the term
"same scope".

[vicious snip]

> Everything the standard currently says about "same scope" still applies, 
> but providing a special definition of "same scope" is no longer needed: 
> two scopes are the same if and only if they start an end at the same place.

A good goal, but I'm still not convinced that inventing a new term,
rather than using something like "matching scope" rather than "same
scope", is necessary.

> I have not bothered doing a comprehensive search of the places where 
> "scope" is used, so I'm not sure which cases should be changed to refer 
> to "visibilty range", and which ones require a more complicated 
> re-write, but I think the last three paragraphs above cover the 
> trickiest issues. I hope the idea is clear from that explanation; if 
> not, I can expand on it in response to sufficiently specific questions.


-- 
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


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