169Fermer171
squalylLe 16/11/2009 à 18:02
je me suis rendu compte que si les fonctions que tu veux appeler ont des args différents, faudra plein de casts partout

typedef int (*boo_t) (int a, char b);
typedef void (*yar_o) (void *a, int b);

(tripo les noms)

int zeboo(int a, char b) { ......blabla }
void zeyar(void *a, int b) { ...... blublu }

void * tableau[2] = {
(void*)zeboo,
(void*)zeyar,
};

a l'utilisation
..... {
boo_t boo;
int blabla;
boo=(boo_t)tableau[0];
blabla = boo(3, (char)42);
}

..... {
yar_o yar;
yar = (yar_o)tableau[1];
yar(NULL,42);
}

ou sans variable intermédiaire comme cross-suggéré par Zephyr:

((yar_o)tableau[1])(NULL,42);

ça fait le code que tu veux oui ('fin, presque sûr)