Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Is the compiler allowed to modify padding bytes

Suppose I have a snippet of code like this (and assume that the padding is inserted as I say in the comment):

#include "stdint.h"

struct A
{
    uint8_t x;
    // 3 bytes of padding
    uint32_t y;
};


void foo(struct A* a)
{
    a->x = 0;
}

Is the compiler allowed to clear the padding bytes or do anything to the padding bytes in the function foo?

https://en.cppreference.com/w/c/language/object is silent on this issue, which leads me to believe that yes the compiler is allowed to do this....

The reason that I want to know whether or not the compiler is allowed to do this is I want to memcmp two structs, and I want to know what I am allowed to assume....

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes. C 2018 6.2.6.1 6 says:

When a value is stored in an object of structure or union type, including in a member object, the bytes of the object representation that correspond to any padding bytes take unspecified values…

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda