1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
typedef struct toto {
int x ;
int y ;
} toto ;
fonction ( void *valeur, int TYPE )
{
double *d = (double *)valeur ;
int *i=(int *)valeur ;
toto *to=(toto *)valeur ;
switch ( TYPE )
{
case DOUBLE :
*d = 3.125 ;
break ;
case INTEGER :
*i=123 ;
break ;
case MASTRUCT :
to->x = 0 ;
ti->y = 1 ;
break ;
....
}
.....
}
{
....
double d ;
int i ;
toto to ;
switch ( TYPE )
{
case DOUBLE :
fonction ( (void *)&d, DOUBLE);
fprintf ( stdout, "\nLe resultat pour double est : %g\n",d);
break ;
case INTEGER :
fonction ( (void *)&i, INTEGER);
fprintf ( stdout, "\nLe resultat pour entier est : %d\n",i);
break ;
case MASTRUCT :
fonction ( (void *)&to, MASTRUCT);
fprintf ( stdout, "\nLe resultat pour structure est : x=%d y=%d\n",to.x,to.y);
break ;
} |
Partager