struct {
truc *(tab[7]);
}machin;
machin est un struct dont le champ tab est un tableau de 7 pointeurs sur des truc.
Si tu as des pointeurs sur différents types dans ton tableau, tu fais
void *(tab[7]); et tu castes.
Autre possibilité, déclarer tes types pointeurs sur différentes choses dans une union:
typedef union {
bidule *bid;
chose *choz;
} truc;
struct {
truc tab[7];
} machin;
Concrètement, un exemple de chaque technique:
Code :
- #include <stdio.h>
- int main()
- {
- struct {
- void *(tab[2]);
- } machin;
- int a = 3;
- char b = 'A';
- machin.tab[0] = (void *) &a;
- machin.tab[1] = (void *) &b;
- printf("%d %c\n", *(int *)machin.tab[0], *(char *)machin.tab[1]);
-
- return 0;
- }
|
Code :
- #include <stdio.h>
- int main()
- {
- typedef union {
- int *pint;
- char *pchar;
- } truc;
- struct {
- truc tab[2];
- } machin;
- int a = 3;
- char b = 'A';
- machin.tab[0].pint = &a;
- machin.tab[1].pchar = &b;
- printf("%d %c\n", *machin.tab[0].pint, *machin.tab[1].pchar);
-
- return 0;
- }
|
La seconde solution permet au compilo de mieux faire son boulot de vérification du bon typage.
A+,
Message édité par gilou le 10-04-2013 à 02:32:29
---------------
There's more than what can be linked! -- Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- No jab ? No job ! -- (╯°□°)╯︵ ┻━┻