Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #106799
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: for-loop scopes |
| Date | 2017-03-23 13:45 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ob0jcu$tuo$1@dont-email.me> (permalink) |
| References | <ob0drl$agb$1@dont-email.me> <ob0hhm$n9j$1@dont-email.me> |
On 23/03/2017 13:14, David Brown wrote:
> On 23/03/17 13:11, BartC wrote:
>> double i; // scope 1
>> for (int i=0; i<10; ++i) // scope 2
>> i; // scope 2
>> i; // scope 1, deliberate misalignment
>> I'm just asking because I'm finding it hard to believe that those last
>> two final 'i' terms switch types with merely an intervening ';'.
>>
>
> You don't think it odd that the first "i" is a statement expression
> executed 10 times within the loop while the second "i" is executed
> outside the loop
That's a little bit less odd, but then you know that C loop bodies might
not end with a specific delimiter such as '}'; it could be just ';'
- but you /do/ find it odd that the first "i" is in a
> different scope from the second one? That strikes me as a very strange
> opinion.
Yes; that the first 'i' in 'i;i;' is an int, and the second might be a
struct, is /more/ odd! You get used to scopes being delimited with {...}.
It is possible to have a scope end half-way through a block, but that is
signalled by a new declaration at that point.
I suppose it is just necessary to imagine the entire for-loop, complete
with body, enclosed in {...}.
--
bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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