Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
October 05, 2002 BUG: Duplicate variable names allowed inside if() block | ||||
---|---|---|---|---|
| ||||
This program goes through the compiler ok, although I believe it should be a syntax error: int main() { int bar; if(true) { int bar; } return 0; } -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
October 07, 2002 Re: Duplicate variable names allowed inside if() block | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D9F31D9.F0F445CD@deming-os.org... > This program goes through the compiler ok, although I believe it should be a syntax error: > > int main() { > int bar; > if(true) { > int bar; > } > return 0; > } It is legal, as { } introduces a new scope. -Walter |
October 07, 2002 Re: Duplicate variable names allowed inside if() block | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | > It is legal, as { } introduces a new scope. -Walter
Oh, I thought that duplicate local variables weren't allowed in D.
You've written it in the language specs:
"It is an error to declare a local variable that hides another local
variable in the same function"
|
October 07, 2002 Re: Duplicate variable names allowed inside if() block | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | I thought you said locals that hide other locals are an error. Sean "Walter" <walter@digitalmars.com> wrote in message news:ans8cq$113g$1@digitaldaemon.com... > > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D9F31D9.F0F445CD@deming-os.org... > > This program goes through the compiler ok, although I believe it should be a syntax error: > > > > int main() { > > int bar; > > if(true) { > > int bar; > > } > > return 0; > > } > > It is legal, as { } introduces a new scope. -Walter |
October 07, 2002 Re: Duplicate variable names allowed inside if() block | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D9F31D9.F0F445CD@deming-os.org... > > This program goes through the compiler ok, although I believe it should be a syntax error: > > > > int main() { > > int bar; > > if(true) { > > int bar; > > } > > return 0; > > } > > It is legal, as { } introduces a new scope. -Walter I knew that used to be true in C/C++, but I thought that we were getting rid of that. Oh well :) -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
October 07, 2002 Re: Duplicate variable names allowed inside if() block | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | You're right, my goof. I'll log it as a bug. -Walter "Dario" <supdar@yahoo.com> wrote in message news:ansdvl$m59$1@digitaldaemon.com... > > It is legal, as { } introduces a new scope. -Walter > > Oh, I thought that duplicate local variables weren't allowed in D. > You've written it in the language specs: > "It is an error to declare a local variable that hides another local > variable in the same function" > > |
Copyright © 1999-2021 by the D Language Foundation