News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Computed goto

Started by akko, July 17, 2009, 12:42:51 PM

Previous topic - Next topic

akko

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

"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

#2
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