Oulah, c'est très compliqué cette affaire. On en avait parlé avec Dargor sur #linux il y a très longtemps et il me que la conclusion était qu'il NE fallait PAS faire de cast explicite pour malloc.
Donc le mieux serait :
entier1 = malloc(sizeof(int)) ;
[... petit saut sur wikipedia ... ]
« You will sometimes see code in which the value returned by malloc is "cast" (see type conversion) to a specific type, as in
int *ptr = (int*)malloc(10 * sizeof (int));.
But this is bad practice: it is redundant under the C standard, as noted above; and moreover, putting in a cast may mask failure to include the header, stdlib.h, in which the prototype for malloc is found. In the absence of a prototype for malloc, the C compiler will assume that malloc returns an int, and will issue a warning in a context such as the above — provided the error is not masked by a cast. (A cast says, in effect, "Don't warn me, I know what I'm doing!" Casts should therefore be used sparingly.)
»
ah oui, déjà on évite les erreurs du à l'oubli d'include de <stdlib.h>.
Il me semble qu'il y avait une autre raison (portabilité ? cross-compilation ?) mais je ne me souviens plus, et je n'ai malheureusement pas bookmarqué le lien sur lequel on était tombé à l'époque. 