NO

Author Topic: Computed goto  (Read 3759 times)

akko

  • Guest
Computed goto
« on: July 17, 2009, 12:42:51 PM »
Maybe it's an old question. But I can't seem to get computed gotos to work (or I am doing s.th. wrong).

static void *array[2] = { &&fvm_doa, &&fvm_dob, &&fvm_doc };

goto *array[1]; // -> should go to fvm_dob ???

fvm_doa:
...
fvm_dob:
...
fvm_doc:
...

Any ideas?

Thanks Andreas

nicolas.sitbon

  • Guest
Re: Computed goto
« Reply #1 on: July 17, 2009, 01:29:21 PM »
"Labels as values" is a GCC extension not present in the C standard and in Pelles C compiler.
http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Labels-as-Values.html#Labels-as-Values

Seltsamuel

  • Guest
Re: Computed goto
« Reply #2 on: July 19, 2009, 03:47:32 PM »
Hi,

this way should work like you want:
You must make the right typedef for your type/types of functions!!


typedef int (__stdcall *P_Interface)(void);

int Function_doa(void)
{
 return 1;
}

int Function_dob(void)
{
 return 2;
}

int Function_doc(void)
{
 return 3;
}

int Function_dod(void)
{
 return 4;
}


FARPROC table[]=
{
   Function_doa,
   Function_dob,
   Function_doc,
   Function_dod
};

int Test(void)
{

   (P_Interface)table[1](); //executes Function_dob

   return 0;
};


Greetings

Seltsamuel
« Last Edit: July 19, 2009, 04:00:21 PM by Seltsamuel »