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


Groups > comp.lang.c > #106843

Re: for-loop scopes

Newsgroups comp.lang.c
Date 2017-03-23 12:33 -0700
References <ob0drl$agb$1@dont-email.me> <828e6fda-e420-4060-9339-0e699adfffd0@googlegroups.com> <ob12nn$o7g$1@dont-email.me>
Message-ID <1638e344-efec-45f2-ac8d-4dd2e3061632@googlegroups.com> (permalink)
Subject Re: for-loop scopes
From jameskuyper@verizon.net

Show all headers | View raw


On Thursday, March 23, 2017 at 2:07:43 PM UTC-4, Bart wrote:
> On 23/03/2017 17:23, Rick C. Hodgin wrote:
> 
> > In your compiler, you surely have mechanisms to perform this kind
> > of search up the chain of scopes to find the suitable match?  I
> > was very surprised by your question.
> 
> The mechanism for resolving names is there. What wasn't there was a 
> mechanism for inventing impromptu scopes out of nowhere!
> 
> A C for-statement doesn't have the concept of a controlling loop 
> variable, but it does now have a private scope...
> 
> -- 
> bartc

"If the declarator or type specifier that declares the identifier appears inside
a block or within the list of parameter declarations in a function definition,
the identifier has block scope, which terminates at the end of the associated
block." (6.2.1p4)

6.8p5 describes iteration statements, which include, in particuar, for
statements.

"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." (6.8.5p5)

It's only the first sentence that is new in C99. Since both scopes end in the
same location (at the end of the loop body), they are considered to be the same
scope (6.2.1p6). Therefore, the scope that you're complaining about is not new
in C99, it's just bigger than it was in C90.

What does "private scope" mean to you? As far as C is concerned, there's no
distinction between this scope and any other kind of block scope.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

for-loop scopes BartC <bc@freeuk.com> - 2017-03-23 12:11 +0000
  Re: for-loop scopes David Brown <david.brown@hesbynett.no> - 2017-03-23 14:14 +0100
    Re: for-loop scopes BartC <bc@freeuk.com> - 2017-03-23 13:45 +0000
      Re: for-loop scopes David Brown <david.brown@hesbynett.no> - 2017-03-23 15:48 +0100
      Re: for-loop scopes Robert Wessel <robertwessel2@yahoo.com> - 2017-03-23 23:01 -0500
        Re: for-loop scopes BartC <bc@freeuk.com> - 2017-03-24 10:27 +0000
          Re: for-loop scopes jameskuyper@verizon.net - 2017-03-24 10:43 -0700
          Re: for-loop scopes Robert Wessel <robertwessel2@yahoo.com> - 2017-03-26 21:57 -0500
  Re: for-loop scopes Keith Thompson <kst-u@mib.org> - 2017-03-23 08:37 -0700
  Re: for-loop scopes Ike Naar <ike@iceland.freeshell.org> - 2017-03-23 16:31 +0000
  Re: for-loop scopes "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-03-23 10:23 -0700
    Re: for-loop scopes BartC <bc@freeuk.com> - 2017-03-23 18:07 +0000
      Re: for-loop scopes David Brown <david.brown@hesbynett.no> - 2017-03-23 20:05 +0100
      Re: for-loop scopes jameskuyper@verizon.net - 2017-03-23 12:33 -0700
      Re: for-loop scopes John Bode <jfbode1029@gmail.com> - 2017-03-24 11:35 -0700
  Re: for-loop scopes Noob <root@127.0.0.1> - 2017-03-23 21:06 +0100
  Re: for-loop scopes Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-03-28 19:15 -0700
    Re: for-loop scopes Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-03-28 19:19 -0700
    Re: for-loop scopes supercat@casperkitty.com - 2017-03-29 13:14 -0700

csiph-web