Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 20, 2004 Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
This bug could exist in the compiler, the spec, or my brain, depending on how you look at it. :) Should this be legal? int main() { if (true) { printf("tautology is neat"); } version (None) { else { // line 6 printf("But paradox makes for a better screenplay"); } } return 0; // line 10 } The error is test.d(6): found 'else' instead of statement test.d(10): Declaration expected, not 'return' test.d(11): unrecognized declaration -- andy |
July 20, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | In article <cdjsdn$1r1o$1@digitaldaemon.com>, Andy Friesen says... > >This bug could exist in the compiler, the spec, or my brain, depending on how you look at it. :) > >Should this be legal? > > int main() { > if (true) { > printf("tautology is neat"); > } > version (None) { > else { // line 6 > printf("But paradox makes for a better screenplay"); > } > } > return 0; // line 10 > } I would say no. Whether or not "None" is defined, the code is not syntactically correct. This is a good example of why language features such as version are much better than preprocessor macros :) >The error is > > test.d(6): found 'else' instead of statement > test.d(10): Declaration expected, not 'return' > test.d(11): unrecognized declaration Seems reasonable. The misplaced "else" clause is confusing the compiler. I'd ignore all errors after the first. Sean |
July 21, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | 'else' is also allowed in the context of 'version'.
version(Win32) {
// Windows code
}
else {
// code for real OS's
}
Andy Friesen wrote:
> This bug could exist in the compiler, the spec, or my brain, depending on how you look at it. :)
>
> Should this be legal?
>
> int main() {
> if (true) {
> printf("tautology is neat");
> }
> version (None) {
> else { // line 6
> printf("But paradox makes for a better screenplay");
> }
> }
> return 0; // line 10
> }
>
> The error is
>
> test.d(6): found 'else' instead of statement
> test.d(10): Declaration expected, not 'return'
>
> test.d(11): unrecognized declaration
>
> -- andy
|
July 21, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | Andy Friesen wrote: <snip> > Should this be legal? > > int main() { > if (true) { > printf("tautology is neat"); > } > version (None) { > else { // line 6 > printf("But paradox makes for a better screenplay"); > } > } > return 0; // line 10 > } <snip> No. But this should: int main() { if (true) { printf("tautology is neat"); } else version (None) { printf("But paradox makes for a better screenplay"); } return 0; } I've noticed in the spec that a literal if(0) is supposed to lead to 'conditional' _compilation_, but is it the same with if(true)? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
July 21, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | In article <cdlfl4$2hu7$1@digitaldaemon.com>, Stewart Gordon says... > >Andy Friesen wrote: > ><snip> >> Should this be legal? >> >> int main() { >> if (true) { >> printf("tautology is neat"); >> } >> version (None) { >> else { // line 6 >> printf("But paradox makes for a better screenplay"); >> } >> } >> return 0; // line 10 >> } ><snip> > >No. But this should: > > int main() { > if (true) { > printf("tautology is neat"); > } > else version (None) { > printf("But paradox makes for a better screenplay"); > } > return 0; > } I don't know if the other versions should work, but this version does: #int main() { # if (true) { # printf("tautology is neat"); # } # else { # version (None) { # printf("But paradox makes for a better screenplay"); # } # } # return 0; #} Hope that helps some. > >I've noticed in the spec that a literal if(0) is supposed to lead to 'conditional' _compilation_, but is it the same with if(true)? > >Stewart. > >-- >My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. jcc7 |
July 21, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese wrote:
> I don't know if the other versions should work, but this version does:
>
> #int main() {
> # if (true) {
> # printf("tautology is neat");
> # }
> # else {
> # version (None) {
> # printf("But paradox makes for a better screenplay");
> # } # }
> # return 0;
> #}
>
>
> Hope that helps some.
Sort of, but not really. I came across the 'bug' as a result of a little source code preprocessing app. (converting DMD to D)
Apparently, DMD sets higher standards than the ones it follows. ;)
-- andy
|
July 22, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cabal | "Cabal" <cabalN05P4M@myrealbox.com> escribió en el mensaje news:cdl5hf$2cl3$1@digitaldaemon.com | 'else' is also allowed in the context of 'version'. | | version(Win32) { | // Windows code | } | else { | // code for real OS's | } | I think that's completely different to what Andy wanted to do. | | Andy Friesen wrote: | || This bug could exist in the compiler, the spec, or my brain, depending || on how you look at it. :) || || Should this be legal? || || int main() { || if (true) { || printf("tautology is neat"); || } || version (None) { || else { // line 6 || printf("But paradox makes for a better screenplay"); || } || } || return 0; // line 10 || } || || The error is || || test.d(6): found 'else' instead of statement || test.d(10): Declaration expected, not 'return' || || test.d(11): unrecognized declaration || || -- andy ----------------------- Carlos Santander Bernal |
July 22, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | On Tue, 20 Jul 2004 12:43:48 -0700, Andy Friesen wrote: > This bug could exist in the compiler, the spec, or my brain, depending on how you look at it. :) > > Should this be legal? > > int main() { > if (true) { > printf("tautology is neat"); > } > version (None) { > else { // line 6 > printf("But paradox makes for a better screenplay"); > } > } > return 0; // line 10 > } > > The error is > > test.d(6): found 'else' instead of statement > test.d(10): Declaration expected, not 'return' > > test.d(11): unrecognized declaration > > -- andy I suspect this is how it is supposed to be written ... <code> int main() { version (None) { if (true) { printf("tautology is neat"); } else { // line 6 printf("But paradox makes for a better screenplay"); } } else { if (true) { printf("tautology is neat"); }; } return 0; // line 10 } </code> -- Derek Melbourne, Australia 22/Jul/04 2:43:52 PM |
July 22, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | On Thu, 22 Jul 2004 14:44:32 +1000, Derek Parnell <derek@psych.ward> wrote: > On Tue, 20 Jul 2004 12:43:48 -0700, Andy Friesen wrote: > >> This bug could exist in the compiler, the spec, or my brain, depending >> on how you look at it. :) >> >> Should this be legal? >> >> int main() { >> if (true) { >> printf("tautology is neat"); >> } >> version (None) { >> else { // line 6 >> printf("But paradox makes for a better screenplay"); >> } >> } >> return 0; // line 10 >> } >> >> The error is >> >> test.d(6): found 'else' instead of statement >> test.d(10): Declaration expected, not 'return' >> >> test.d(11): unrecognized declaration >> >> -- andy > > I suspect this is how it is supposed to be written .. > <code> > > int main() { > version (None) { > if (true) { > printf("tautology is neat"); > } > else { // line 6 > printf("But paradox makes for a better screenplay"); > } > } > else > { > if (true) { > printf("tautology is neat"); > }; > } > return 0; // line 10 > } > > </code> Yeah.. but that is somewhat more verbose than the original. Is this equivalent to the original? void main() { if (true) { printf("tautology is neat"); } else { version (None) { printf("But paradox makes for a better screenplay"); } } } Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
July 22, 2004 Re: Bug? Else clause in version statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | On Thu, 22 Jul 2004 17:12:02 +1200, Regan Heath wrote: > On Thu, 22 Jul 2004 14:44:32 +1000, Derek Parnell <derek@psych.ward> wrote: >> On Tue, 20 Jul 2004 12:43:48 -0700, Andy Friesen wrote: >> >>> This bug could exist in the compiler, the spec, or my brain, depending on how you look at it. :) >>> >>> Should this be legal? >>> >>> int main() { >>> if (true) { >>> printf("tautology is neat"); >>> } >>> version (None) { >>> else { // line 6 >>> printf("But paradox makes for a better screenplay"); >>> } >>> } >>> return 0; // line 10 >>> } >>> >>> The error is >>> >>> test.d(6): found 'else' instead of statement >>> test.d(10): Declaration expected, not 'return' >>> >>> test.d(11): unrecognized declaration >>> >>> -- andy >> >> I suspect this is how it is supposed to be written .. <code> >> >> int main() { >> version (None) { >> if (true) { >> printf("tautology is neat"); >> } >> else { // line 6 >> printf("But paradox makes for a better screenplay"); >> } >> } >> else >> { >> if (true) { >> printf("tautology is neat"); >> }; >> } >> return 0; // line 10 >> } >> >> </code> > > Yeah.. but that is somewhat more verbose than the original. Is this equivalent to the original? > > void main() { > if (true) { > printf("tautology is neat"); > } > else { > version (None) { > printf("But paradox makes for a better screenplay"); > } > } > } > > Regan. Oh your code is much neater. I forgot that "else{}" is a useful construct. -- Derek Melbourne, Australia 22/Jul/04 3:37:47 PM |
Copyright © 1999-2021 by the D Language Foundation