Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!