Re: Inside the switch statement

2009-06-15 Thread Joel C. Salomon
Kagamin wrote: > The Duff's device is said to be an optimization, but I get blunt device only > 0.7% slower. Read Duff’s post: “this loop was the bottleneck in a real-time animation playback program”, and all the Device is doing is unwinding the loop a few times. Optimization comes because — on

Re: Inside the switch statement

2009-06-11 Thread bearophile
Kagamin: > The Duff's device is said to be an optimization, but I get blunt device only > 0.7% slower. Compilers already know about the Duff's device, and sometimes they use it automatically. Bye, bearophile

Re: Inside the switch statement

2009-06-11 Thread Kagamin
> template duffs_device(alias id1, alias id2, alias s) > { > void duff_loop() > { > if (id1 < id2) > { > typeof(id1) n = (id2 - id1 + 7) / 8; > switch ((id2 - id1) % 8) > { > case 0:do { s(); > case 7:

Re: Inside the switch statement

2009-06-10 Thread Steve Schveighoffer
On Tue, 09 Jun 2009 19:35:51 +0200, Saaa wrote: >>> What kind of fall-throughs were these? >>> >>> A: >>> >>> case value1: >>> case value2: >>> case valueN: >>> code1(); >>> break; >>> >>> B: >>> >>> case value1: >>> code1(); >>> case value2: >>> code2(); >>> break; >> >> The s

Re: Inside the switch statement

2009-06-09 Thread BCS
Hello Derek, On Tue, 9 Jun 2009 16:28:58 + (UTC), BCS wrote: I'm sorry, you don't have my sympathy on this one. There are to many place I've used fall throught to chuck it out. [...] However, additionally in the default format you can use 'fallthru' to let flow drop to the next case

Re: Inside the switch statement

2009-06-09 Thread Derek Parnell
On Tue, 9 Jun 2009 16:28:58 + (UTC), BCS wrote: > Hello grauzone, > >>> http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c >>> >> Many people (even Brian Kernighan?) have said that the worst feature >> of C is that switches don't break automatically before each case >> label. >>

Re: Inside the switch statement

2009-06-09 Thread BCS
Hello Ary, Saaa wrote: You missed the alternative syntax to get the same behaviour. But it's a very subtle difference. Do you mean the multiple cases? http://www.digitalmars.com/d/1.0/statement.html#SwitchStatement Yes, but make the "multiple cases" the *only* way to make case statements fa

Re: Inside the switch statement

2009-06-09 Thread Saaa
> Write a lexer and a parser. how do you mean?

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
Saaa wrote: (nah, just kidding, you're right, I didn't realize it :-P) Ok, enough kidding around, lets get back to you helping me with 'code generalization' :P Write a lexer and a parser.

Re: Inside the switch statement

2009-06-09 Thread Saaa
(nah, just kidding, you're right, I didn't realize it :-P) Ok, enough kidding around, lets get back to you helping me with 'code generalization' :P

Re: Inside the switch statement

2009-06-09 Thread Saaa
> Well, yes, but you also have to prepare your mind for the change. This > is a huge step. ;)

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
Saaa wrote: Yes, but make the "multiple cases" the *only* way to make case statements fallthrough. That would be the change. That is the same as giving an error on case B, right? Well, yes, but you also have to prepare your mind for the change. This is a huge step. (nah, just kidding, you'

Re: Inside the switch statement

2009-06-09 Thread Saaa
I mean, the syntax stays the same.

Re: Inside the switch statement

2009-06-09 Thread Saaa
> Yes, but make the "multiple cases" the *only* way to make case > statements fallthrough. That would be the change. That is the same as giving an error on case B, right?

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
Saaa wrote: You missed the alternative syntax to get the same behaviour. But it's a very subtle difference. Do you mean the multiple cases? http://www.digitalmars.com/d/1.0/statement.html#SwitchStatement Yes, but make the "multiple cases" the *only* way to make case statements fallthrough.

Re: Inside the switch statement

2009-06-09 Thread Saaa
> You missed the alternative syntax to get the same behaviour. But it's a > very subtle difference. Do you mean the multiple cases? http://www.digitalmars.com/d/1.0/statement.html#SwitchStatement

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
Saaa wrote: How do you know? BCS didn't reply to my idea. Your idea was to give an error on the case (B) he uses. Or did I miss something? You missed the alternative syntax to get the same behaviour. But it's a very subtle difference.

Re: Inside the switch statement

2009-06-09 Thread Saaa
> How do you know? BCS didn't reply to my idea. Your idea was to give an error on the case (B) he uses. Or did I miss something?

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
Saaa wrote: What's wrong with that? Doesn't support B :) How about a warning instead? The idea is that it not supporting B is something good. I know this is your idea, but as BCS doesn't support this idea. How do you know? BCS didn't reply to my idea. You should have replied to him iso gr

Re: Inside the switch statement

2009-06-09 Thread Saaa
>>> What's wrong with that? >> >> Doesn't support B :) >> >> How about a warning instead? > > The idea is that it not supporting B is something good. I know this is your idea, but as BCS doesn't support this idea. You should have replied to him iso grauzone. I personally never had any problems wit

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
Saaa wrote: What kind of fall-throughs were these? A: case value1: case value2: case valueN: code1(); break; B: case value1: code1(); case value2: code2(); break; The solution is to forbid fallthrough, and change the switch syntax: switch(value) { case 1: case 2: //

Re: Inside the switch statement

2009-06-09 Thread Saaa
>> What kind of fall-throughs were these? >> >> A: >> >> case value1: >> case value2: >> case valueN: >> code1(); >> break; >> >> B: >> >> case value1: >> code1(); >> case value2: >> code2(); >> break; > > The solution is to forbid fallthrough, and change the switch syntax: > >

Re: Inside the switch statement

2009-06-09 Thread Ary Borenszweig
grauzone wrote: BCS wrote: Hello grauzone, http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today we'

Re: Inside the switch statement

2009-06-09 Thread BCS
Hello grauzone, BCS wrote: Hello grauzone, http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today w

Re: Inside the switch statement

2009-06-09 Thread grauzone
BCS wrote: Hello grauzone, http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today we're struggling wit

Re: Inside the switch statement

2009-06-09 Thread BCS
Hello grauzone, http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today we're struggling with this bulls

Re: Inside the switch statement

2009-06-09 Thread grauzone
http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c >Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today we're struggling with this bullshit in the mos

Re: Inside the switch statement

2009-06-08 Thread Sam Hu
Thanks so much for all your help!I am studying hard to *loop unrolling*. > BTW: where is this from? It is from the spec: http://www.digitalmars.com/d/1.0/template-mixin.html BTW,is this Duff? http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c

Re: Inside the switch statement

2009-06-08 Thread Ellery Newcomer
BCS wrote: > Hello Sam, > >> To save time ,just get to my point:I do not understand why such code >> below inside the switch ... case statement is allowed ,what is the >> point of do ... while...: > > This is a classic C thing. The short explanation is that a switch is a > conditional, many way g

Re: Inside the switch statement

2009-06-08 Thread BCS
Hello Sam, To save time ,just get to my point:I do not understand why such code below inside the switch ... case statement is allowed ,what is the point of do ... while...: This is a classic C thing. The short explanation is that a switch is a conditional, many way goto and the labels can be

Inside the switch statement

2009-06-08 Thread Sam Hu
To save time ,just get to my point:I do not understand why such code below inside the switch ... case statement is allowed ,what is the point of do ... while...: This example uses a mixin to implement a generic Duff's device for an arbitrary statement (in this case, the arbitrary statement is i