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


Groups > comp.lang.c > #112045

Scope of identifiers

From Steve Keller <keller@no.invalid>
Newsgroups comp.lang.c
Subject Scope of identifiers
Date 2017-06-12 18:08 +0200
Organization Aioe.org NNTP Server
Message-ID <ohmea9$nft$1@gioia.aioe.org> (permalink)

Show all headers | View raw


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

That section also talks about the beginning of a scope in 6.2.1p7
and says that except for structure, union, and enumeration tags "any
other identifier has scope that begins just after the completion of
its declarator."

But what does that mean in case of

$ nl -ba foo.c
     1  int a;
     2  int *p = &a;
     3  
     4  int foo() {
     5      int foo = 0;
     6      int bar = foo + 1;
     7  }

Paragraph 6.2.1p6 says that 'a' and 'p' have the same scope although
paragraph 6.2.1p7 says that the scope of 'a' begins at the end of line 1
while the scope of 'p' begins in line 2 right before the '='.  IMO,
that looks contradicting, unless you also define that two scopes can
be the same although they begin at different points.  Analoguous for
foo and bar.

Can someone explan this to me?

Steve

Back to comp.lang.c | Previous | Next — 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