bonjour,
je souhaite remplacer plusieurs lignes de codes par une macro :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
	if (msg)
		{
			msg[msg_len] = '\0';
			break;
		}
		msg_len++;
		msg = (char *) malloc(msg_len);
		if (check_not(msg != NULL, "Can't alloc msg"))
		{
			return -1;
		}
ci dessous ma macro qui la remplace :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define END_MSG(msg, msg_len) \
	do { \
		if (msg) \
		{ \
			msg[msg_len] = '\0'; \
			break; \
	    } \
		msg_len++; \
		msg = (char *) malloc(msg_len); \
		if (check_not(msg != NULL, "Can't alloc msg")) \
		{ \
			return -1; \
		} \
	} while(0)
la macro me donne un problème , autrement dis l'allocation mémoire ne se fais pas ! (j'ai bien essaye if (msg == NULL) ... )

ma macro est t'elle mal écrite ?
Merci d'avance.