A compiler may insert one or more unused whole bytes after a structure member so the next member begins at a suitable alignment boundary. Padding can follow any member, but never begins a structure. section 6.3.4
Keep these layout rules in mind:
- Member order remains the declared order, even when alignment introduces wasted space. section 6.3.4
- Reordering members can reduce wasted padding bytes, although the resulting layout still depends on compiler alignment choices. section 6.3.4
- Do not confuse byte padding with bit padding: bit padding can waste individual bits, including inside unsigned values. section 6.3.4
// *** This has errors, don't use it! ***
struct tib {
int tib_sec :6; // Seconds after the minute [0, 60]
int tib_min :6; // Minutes after the hour [0, 59]
int tib_hour :5; // Hours since midnight [0, 23]
int tib_mday :5; // Day of the month [1, 31]
int tib_mon :4; // Months since January [0, 11]
int tib_year; // Years since 1900
int tib_wday :3; // Days since Sunday [0, 6]
int tib_yday :9; // Days since January [0, 365]
int tib_isdst:1; // Daylight Saving Time flag
};
Use this bit-field listing as a contrast with byte padding; its comments show compact bit allocation, and the listing is explicitly marked as erroneous. section 6.3.4


















