digitalmars.D.bugs - Bug? Else clause in version statement
- Andy Friesen (19/19) Jul 20 2004 This bug could exist in the compiler, the spec, or my brain, depending
- Sean Kelly (7/25) Jul 20 2004 I would say no. Whether or not "None" is defined, the code is not synta...
- Cabal (8/33) Jul 21 2004 'else' is also allowed in the context of 'version'.
-
Carlos Santander B.
(42/42)
Jul 21 2004
"Cabal"
escribió en el mensaje - Cabal (3/4) Jul 21 2004 I wasn't trying to second guess him. I was just pointing out why what he...
-
Stewart Gordon
(20/33)
Jul 21 2004
- J C Calvarese (15/48) Jul 21 2004 I don't know if the other versions should work, but this version does:
- Andy Friesen (5/21) Jul 21 2004 Sort of, but not really. I came across the 'bug' as a result of a
- Derek Parnell (25/50) Jul 21 2004 I suspect this is how it is supposed to be written ...
- Regan Heath (16/62) Jul 21 2004 Yeah.. but that is somewhat more verbose than the original.
- Derek Parnell (6/73) Jul 21 2004 Oh your code is much neater. I forgot that "else{}" is a useful construc...
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
Jul 20 2004
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 declarationSeems reasonable. The misplaced "else" clause is confusing the compiler. I'd ignore all errors after the first. Sean
Jul 20 2004
'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
Jul 21 2004
"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
Jul 21 2004
Carlos Santander B. wrote:think that's completely different to what Andy wantedI wasn't trying to second guess him. I was just pointing out why what he had done wasn't going to work...
Jul 21 2004
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.
Jul 21 2004
In article <cdlfl4$2hu7$1 digitaldaemon.com>, Stewart Gordon says...Andy Friesen wrote: <snip>I don't know if the other versions should work, but this version does: #int main() { Hope that helps some.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.jcc7
Jul 21 2004
J C Calvarese wrote:I don't know if the other versions should work, but this version does: #int main() { 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
Jul 21 2004
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 -- andyI 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
Jul 21 2004
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: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/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 -- andyI 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>
Jul 21 2004
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:Oh your code is much neater. I forgot that "else{}" is a useful construct. -- Derek Melbourne, Australia 22/Jul/04 3:37:47 PMOn Tue, 20 Jul 2004 12:43:48 -0700, Andy Friesen wrote: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.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 -- andyI 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>
Jul 21 2004