
Envoyé par
deck_bsd
1 2 3 4 5
| char * ptChaine;
ptChaine = (char*)malloc(sizeof(char)*tailleDeLaChaine);
free(ptChaine); |
- Pourquoi le cast ?
- sizeof (char) fait 1 par défintion.
- Tu ecris du code inutilement compliqué.
char * ptChaine = malloc (tailleDeLaChaine);
ou, si le type peut evoluer (wchar_t, par exemple)
char * ptChaine = malloc (sizeof *ptChaine * tailleDeLaChaine);
et après avoir libéré, remettre le pointeur à NULL :
free(ptChaine), ptChaine = NULL;
http://emmanuel-delahaye.developpez....tes.htm#malloc
Partager