Get address of label?

Simen kjaeraas simen.kjaras at gmail.com
Sat Dec 25 11:03:45 PST 2010


Heywood Floyd <soul8o8 at gmail.com> wrote:

> Is this possible somehow:
>      int op(int r, int i)
>     {
>         static auto tbl = [&add, &sub, &mul];
>         goto tbl[i % 3];
>            add:
>             r++;
>             goto end;
>         sub:
>             r--;
>             goto end;
>         mul:
>             r*=r;
>             goto end;
>         end:
>         return r;
>     }

Absolutely:

enum ops : int {
     add = 0,
     sub = 1,
     mul = 2;
}

int op( int r, int i ) {
     switch( i % 3 ) {
         case add:
             r++;
             break;
         case sub:
             r--;
             break;
         case mul:
             r*=r;
             break;
     }
     return r;
}

-- 
Simen


More information about the Digitalmars-d-learn mailing list