Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 13, 2002 scope of variable declared in for-loop | ||||
---|---|---|---|---|
| ||||
What is the current scope of the index declared in for loops in dmc? A few years ago, it appeared that SC, as Visual C, did not obey the new scoping rules specified in the standard. Specifically, what is the scope of i? for(int i=0;i<n;i++){ .... } Ed Sowell |
February 14, 2002 Re: scope of variable declared in for-loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Edward F. Sowell | "Edward F. Sowell" wrote:
> What is the current scope of the index declared in for loops in dmc? A
> few years ago, it appeared
> that SC, as Visual C, did not obey the new scoping rules specified in
> the standard.
>
> Specifically, what is the scope of i?
>
> for(int i=0;i<n;i++){
>
> ....
>
> }
// here the 'i' still exists as far as I know!
I am not even sure whether or not this is part of the latest C++ standards. I know there was a lot of discussion about it when it was introduces and I do seem to remember that it was dropped in favor of existing code...
Jan
|
February 14, 2002 Re: scope of variable declared in for-loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Hi Jan,
According to one of the most widely used C++ texts (Deitel& Deitel), it is
the standard.
Nonetheless, MSVC 6.0 does not follow it. Borland and DJGPP does. When I
tested
SC in about 98, it did not, probably following Microsoft's instincts.
I am not a standards guru, so can't say for sure...
Ed Sowell
Jan Knepper wrote:
> "Edward F. Sowell" wrote:
>
> > What is the current scope of the index declared in for loops in dmc? A
> > few years ago, it appeared
> > that SC, as Visual C, did not obey the new scoping rules specified in
> > the standard.
> >
> > Specifically, what is the scope of i?
> >
> > for(int i=0;i<n;i++){
> >
> > ....
> >
> > }
>
> // here the 'i' still exists as far as I know!
>
> I am not even sure whether or not this is part of the latest C++ standards. I know there was a lot of discussion about it when it was introduces and I do seem to remember that it was dropped in favor of existing code...
>
> Jan
|
February 14, 2002 Re: scope of variable declared in for-loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Jan Knepper schrieb...
> "Edward F. Sowell" wrote:
>
> > What is the current scope of the index declared in for loops in dmc? A
> > few years ago, it appeared
> > that SC, as Visual C, did not obey the new scoping rules specified in
> > the standard.
> >
> > Specifically, what is the scope of i?
> >
> > for(int i=0;i<n;i++){
> >
> > ....
> >
> > }
>
> // here the 'i' still exists as far as I know!
>
> I am not even sure whether or not this is part of the latest C++ standards. I know there was a lot of discussion about it when it was introduces and I do seem to remember that it was dropped in favor of existing code...
No, the standard requires 'i' to be in local scope. Existing code could easyly be adapted to this new rule. BTW, I would like to have this in DMC too, could be enabled/disabled by a compiler switch.
Regards,
Heinz
|
February 14, 2002 Re: scope of variable declared in for-loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz Saathoff | > No, the standard requires 'i' to be in local scope. Existing code could easyly be adapted to this new rule. BTW, I would like to have this in DMC too, could be enabled/disabled by a compiler switch.
Existing code indeed could be easily adopted.
Enabling/disabling this is something that Borland C++ and GNU C++ do AFAIK
Jan
|
Copyright © 1999-2021 by the D Language Foundation