• [^] # Re: Petites precisions

    Posté par . En réponse au journal J'adore Linus. Évalué à 1.

    Et voilà, j'ai une structure qui fait la taille d'un int qui s'utilise comme un int, etc...

    gni ? le rapport ... ?

    De plus la norme (oui oui), autorise :
    (n_importe_quoi *) = (void *)
    et
    (void *) = (n_importe_quoi *)


    la norme autorise la conversion d'un pointeur quelconque en un pointeur générique (void *), et réciproquement, sans perte d'information. De la même façon que tu peux convertir un int en long et tu retrouves la même valeur quand tu reconvertis le long en int. Pourtant int et long n'ont pas nécessairement la même taille.

    Bref sizeof (void *) == sizeof (char *) >= sizeof (autre_chose *)
    A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. [...] All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements.


    pour malloc:
    The pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object or an array of such objects in the space allocated