digitalmars.D.bugs - Bug? Else clause in version statement
- Andy Friesen <andy ikagames.com> Jul 20 2004
- Sean Kelly <sean f4.ca> Jul 20 2004
- Cabal <cabalN05P4M myrealbox.com> Jul 21 2004
- "Carlos Santander B." <carlos8294 msn.com> Jul 21 2004
- Cabal <cabalN05P4M myrealbox.com> Jul 21 2004
- Stewart Gordon <smjg_1998 yahoo.com> Jul 21 2004
- J C Calvarese <jcc7 cox.net> Jul 21 2004
- Andy Friesen <andy ikagames.com> Jul 21 2004
- Derek Parnell <derek psych.ward> Jul 21 2004
- Regan Heath <regan netwin.co.nz> Jul 21 2004
- Derek Parnell <derek psych.ward> Jul 21 2004
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 declaration
Seems 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 wanted
I 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 }
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>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 }
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
Jul 21 2004
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
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 -- 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
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: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/
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: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
Jul 21 2004









Sean Kelly <sean f4.ca> 