digitalmars.D.learn - Should the 2.054 feature about warning on implicit fallthrough include
- simendsjo (15/15) Sep 14 2011 Not sure if this is a bug or as intended.
- bearophile (20/21) Sep 14 2011 The semantics of switch is a mess (example: see http://d.puremagic.com/i...
- Timon Gehr (14/35) Sep 14 2011 I think it is a bit mean to say the whole semantics is a mess, because
- bearophile (14/19) Sep 14 2011 The original C design is a mess with several traps, and successive thing...
- Dmitry Olshansky (6/25) Sep 14 2011 It depends on what you need it to do.
- Timon Gehr (14/31) Sep 14 2011 That's subjective of course. It does not strike me as particularly ugly....
- bearophile (22/25) Sep 14 2011 At the moment I suggest nothing, because the situation is set.
- Timon Gehr (30/55) Sep 14 2011 import std.stdio;
- travert phare.normalesup.org (Christophe) (7/26) Sep 15 2011 If there is a goto aLabel somewhere, the program could go to line 9.
- Dmitry Olshansky (7/22) Sep 14 2011 Label doesn't affect switch statement in any way, e.g. it's not part of
- Timon Gehr (4/19) Sep 14 2011 This is as intended. Labels and case/default statements are not the same...
Not sure if this is a bug or as intended. import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here default: writeln("default"); // But always falls through here aLabel: writeln("a label"); } }
Sep 14 2011
simendsjo Wrote:Not sure if this is a bug or as intended.The semantics of switch is a mess (example: see http://d.puremagic.com/issues/show_bug.cgi?id=3820 ). Mixing labels and switch cases seems a good way to create a bigger mess. If I invert some things in your code I get an error... import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here aLabel: writeln("a label"); default: writeln("default"); // But always falls through here } } Bye, bearophile
Sep 14 2011
On 09/14/2011 09:11 PM, bearophile wrote:simendsjo Wrote:I think it is a bit mean to say the whole semantics is a mess, because there is an accepts-invalid bug. ;) What is really nice about D's case labels, is that they introduce a new scope. (as opposed to C) Unless they are mixed in: http://d.puremagic.com/issues/show_bug.cgi?id=6590 . switch statements and gotos provide nice means of writing highly efficient code that still looks somewhat structured. I don't agree that using labels inside a switch creates a mess.Not sure if this is a bug or as intended.The semantics of switch is a mess (example: see http://d.puremagic.com/issues/show_bug.cgi?id=3820 ). Mixing labels and switch cases seems a good way to create a bigger mess.If I invert some things in your code I get an error... import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here aLabel: writeln("a label"); default: writeln("default"); // But always falls through here } } Bye, bearophileWell, yes, but that is as expected. Would you expect a fall through error on this code? writeln(1); label: writeln(2); labeled statements and case/default statements are not the same thing.
Sep 14 2011
Timon Gehr:I think it is a bit mean to say the whole semantics is a mess,The original C design is a mess with several traps, and successive things added in D to the switch have increased the mess, they were designed from very narrow points of view, with a lack of global vision: 1) The case x: .. case y: syntax is ugly, and it doesn't respect the semantics of the .. in D that means a range open on the right. 2) The introduction of final switches is badly designed and not complete, so the safety of the situation is not improved: http://d.puremagic.com/issues/show_bug.cgi?id=5713 3) The recent improvements (that are patches on the stupid semantics of the C switch) are buggy and need a patch: https://github.com/D-Programming-Language/dmd/pull/370 Switch is too much limited, ignoring other needs: http://d.puremagic.com/issues/show_bug.cgi?id=596 I'll never agree that the C switch is well (or even "well enough") designed. Even a simple language as Pascal gets the case-of statement better than C.switch statements and gotos provide nice means of writing highly efficient code that still looks somewhat structured.I'd like computed gotos in D. I have discussed with Walter often about this, but he doesn't listen much on this.Well, yes, but that is as expected. Would you expect a fall through error on this code?Have you run that code? Bye, bearophile
Sep 14 2011
On 15.09.2011 0:51, bearophile wrote:Timon Gehr:It depends on what you need it to do. If all you need is jump table then C switch is your best friend.I think it is a bit mean to say the whole semantics is a mess,The original C design is a mess with several traps, and successive things added in D to the switch have increased the mess, they were designed from very narrow points of view, with a lack of global vision: 1) The case x: .. case y: syntax is ugly, and it doesn't respect the semantics of the .. in D that means a range open on the right. 2) The introduction of final switches is badly designed and not complete, so the safety of the situation is not improved: http://d.puremagic.com/issues/show_bug.cgi?id=5713 3) The recent improvements (that are patches on the stupid semantics of the C switch) are buggy and need a patch: https://github.com/D-Programming-Language/dmd/pull/370 Switch is too much limited, ignoring other needs: http://d.puremagic.com/issues/show_bug.cgi?id=596 I'll never agree that the C switch is well (or even "well enough") designed. Even a simple language as Pascal gets the case-of statement better than C.+1.switch statements and gotos provide nice means of writing highly efficient code that still looks somewhat structured.I'd like computed gotos in D. I have discussed with Walter often about this, but he doesn't listen much on this.-- Dmitry OlshanskyWell, yes, but that is as expected. Would you expect a fall through error on this code?Have you run that code? Bye, bearophile
Sep 14 2011
On 09/14/2011 10:51 PM, bearophile wrote:Timon Gehr:That's subjective of course. It does not strike me as particularly ugly. (if you'd rather see case x .. y+1:, I think that is exceptionally ugly). The fact that the last case is included is a move to make it more useful. What would you suggest?I think it is a bit mean to say the whole semantics is a mess,The original C design is a mess with several traps, and successive things added in D to the switch have increased the mess, they were designed from very narrow points of view, with a lack of global vision: 1) The case x: .. case y: syntax is ugly, and it doesn't respect the semantics of the .. in D that means a range open on the right.2) The introduction of final switches is badly designed and not complete, so the safety of the situation is not improved: http://d.puremagic.com/issues/show_bug.cgi?id=5713Yah, that is quite messy, but I think that can be fixed.3) The recent improvements (that are patches on the stupid semantics of the C switch) are buggy and need a patch: https://github.com/D-Programming-Language/dmd/pull/370QOI issue, not a fundamental design flaw. I am sure the patch will be applied.Switch is too much limited, ignoring other needs: http://d.puremagic.com/issues/show_bug.cgi?id=596I agree that it would be nice for switch to work on other types. The other needs are better addressed by the introduction of a match expression.I'll never agree that the C switch is well (or even "well enough") designed. Even a simple language as Pascal gets the case-of statement better than C.'C switch' means 'jump table'. It does do that perfectly. ;)+1.switch statements and gotos provide nice means of writing highly efficient code that still looks somewhat structured.I'd like computed gotos in D. I have discussed with Walter often about this, but he doesn't listen much on this.What is your point?Well, yes, but that is as expected. Would you expect a fall through error on this code?Have you run that code?
Sep 14 2011
Timon Gehr:What would you suggest?At the moment I suggest nothing, because the situation is set. Case syntax was discussed a lot, by me too. I suggested to differentiate the syntax, not using ".." because in D they denote an interval open on the right.'C switch' means 'jump table'. It does do that perfectly. ;)C language is full of badly designed parts :-)What is your point?Well, I don't understand the error it gives :-) Are you able to explain it to me? import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here aLabel: writeln("a label"); default: writeln("default"); // But always falls through here } } test.d(10): Error: switch case fallthrough - use 'goto default;' if intended Bye, bearophile
Sep 14 2011
On 09/15/2011 12:43 AM, bearophile wrote:Timon Gehr:import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); // goto default; // NOT needed here (for it to compile) aLabel: writeln("a label"); goto default; // explicit fall through default: writeln("default"); // But always falls through here } } And that is exactly the same as this: import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); writeln("a label"); goto default; // comment this out to get your error back. default: writeln("default"); } } It is a simple case of switch case fallthrough.What would you suggest?At the moment I suggest nothing, because the situation is set. Case syntax was discussed a lot, by me too. I suggested to differentiate the syntax, not using ".." because in D they denote an interval open on the right.'C switch' means 'jump table'. It does do that perfectly. ;)C language is full of badly designed parts :-)What is your point?Well, I don't understand the error it gives :-) Are you able to explain it to me? import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here aLabel: writeln("a label"); default: writeln("default"); // But always falls through here } } test.d(10): Error: switch case fallthrough - use 'goto default;' if intended Bye, bearophile
Sep 14 2011
bearophile , dans le message (digitalmars.D.learn:29532), a écrit :Well, I don't understand the error it gives :-) Are you able to explain it to me? import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here aLabel: writeln("a label"); default: writeln("default"); // But always falls through here } } test.d(10): Error: switch case fallthrough - use 'goto default;' if intendedIf there is a goto aLabel somewhere, the program could go to line 9. Then it should fall to the default statement, but the compiler asks for an explicit fallthrough, since default is not a simple label, but something like a case statement. -- Christophe
Sep 15 2011
On 14.09.2011 22:52, simendsjo wrote:Not sure if this is a bug or as intended. import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here default: writeln("default"); // But always falls through here aLabel: writeln("a label"); } }Label doesn't affect switch statement in any way, e.g. it's not part of case x: synatx, and as such is "fallthrough" like in normal code. So this part works as intended, though I agree with bearophile there are some messy things w.r.t. switch. -- Dmitry Olshansky
Sep 14 2011
On 09/14/2011 08:52 PM, simendsjo wrote:Not sure if this is a bug or as intended. import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here default: writeln("default"); // But always falls through here aLabel: writeln("a label"); } }This is as intended. Labels and case/default statements are not the same thing. As an example, case/default statements introduce a new scope, while labels do not.
Sep 14 2011