Feature Request: Label assignment / type
Bill Baxter
dnewsgroup at billbaxter.com
Sat Nov 17 10:49:25 PST 2007
Janice Caron wrote:
> On 11/17/07, Joe Pusdesris <deformative0 at gmail.com> wrote:
>> I just find it easier for things like jump tables and to specify a point to
>> return to after finishing a block, but if no one else likes it that's cool
>> too.
>
> switch statement often compile to jump tables. Or at least, they did
> in C - I've no idea what the D compiler does. So instead of
>
> Label a = label2;
> goto a;
>
> label1:
> /* stuff */
>
> label2:
> /* stuff */
>
> you do
>
> enum Label { label1, label2 };
> Label a = label2;
> switch (a)
> {
> case label1:
> /* stuff */
>
> case label2:
> /* stuff */
> }
>
> It all boils down to the same thing.
Perfect hashes can/are also be used for that, no?
I'm curious how DMD handles string switches.
switch(name) {
case "bob":
break;
case "betty":
break;
case "barney":
break;
...
}
I imagine something clever is possible to make that really efficient.
But I wouldn't be surprised if it generated code similar to a regular
if-then-else.
--bb
More information about the Digitalmars-d
mailing list