bonjour,

je voudrais déclarer/initialiser une structure. Voici ce que j'ai commencé à faire pour me simplifier la vie :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
// ******************************
// Définition des MACROs
#define TYPE_STR 		1
#define TYPE_UINT32		2
 
// ne focntionne pas => message d'erreur : on ne peut pas concatener x avec le caractère '.'
#define CHAMPS_STR(x, y)   	\
	.##x##.type = TYPE_STR,	\
	.##x##.len = 30, 		\
	.##x##.str = y	
 
#define CHAMPS_UINT32(x, y)		\
	.##x##.type = TYPE_UINT32,	\
	.##x##.len = 4,				\
	.##x##.Val = y	
 
 
 
 
// ******************************
// Déclaration des types
typedef struct _TypeString {
	UINT16	type;
	UINT16	len;
	UINT8	str[30];
} typeString;
 
typedef struct _TypeInt32 {
	UINT16	type;
	UINT16	len;
	UINT32	Val;
} typeInt32;
 
 
 
// ******************************
// Déclaration des types
typedef struct _ZoneMem {
	typeString nomPays;
	typeString nomVille;
	typeInt32 nombreHabitants;
 
	// ...
} ZoneMem;
 
 
 
 
// ******************************
// Declaration de l'empreinte mémoire
/*
ZoneMem myZone = {
	.nomPays.type = TYPE_STR,
	.nomPays.len = 7,
	.nomPays.str = "France",
 
	.nomVille.type = TYPE_STR,
	.nomVille.len = 6,
	.nomVille.str = "Paris",
 
	.nombreHabitants.type = TYPE_UINT32,
	.nombreHabitants.len = 4,
	.nombreHabitants.Val = 123456
};
// */
 
ZoneMem myZone = {
	CHAMPS_STR(nomPays, "France"),
	CHAMPS_STR(nomVille, "Paris"),
 
	CHAMPS_UINT32(nombreHabitants, 123456),
};
J'ai deux problème :
- Mes #define ne compilent pas tous
- Comment faire pour ne pas avoir une taille fixe pour mes chaines afin de pouvoir optimiser la taille en fonction de la taille réelle de la chaine ?

Comment feriez-vous ?

merci d'avance,