• [^] # Re: memset vs {0}

    Posté par (site web personnel, Mastodon) . En réponse à la dépêche Nouveautés du langage C dans sa prochaine version C23. Évalué à 9.

    Bon, déjà ce code ne compile pas parce que l'opérateur != n'est pas défini entre 2 structures.

    Mais admettons qu'on veuille les comparer avec un memcmp par exemple.

    La spécification dit (le dernier brouillon, je n'ai pas la spécification officielle), dans le chapitre 6.7.10 :

    If an object that has automatic storage duration is initialized with an empty initializer, its value is the same as the initialization of a static storage duration object.

    Et donc en cherchant un peu plus loin les règles pour les objets concernés par "static storage duration" :

    If an object that has static or thread storage duration is not initialized explicitly, or is initialized with an empty initializer, then default initialization:
    — if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;

    La réponse est donc oui, le padding est bien initialisé à 0.