size of struct with bitfields greater than expected?
Posted: Wed Oct 11, 2023 8:53 am
Hi, I am new to this forum. I am using the Arduino Framework (ESP8266, ESP32). I am basically trying to understand why the total size of the following structure is not 4 bytes like expected. Instead when I print the size out to the serial terminal, it says 6 bytes.
Code: Select all
typedef struct date_time_stamp {
uint8_t year : 6;
uint8_t month : 4;
uint8_t day : 5;
uint8_t hour : 5;
uint8_t minute : 6;
uint8_t second : 6;
// total size = 32 bits = 4 bytes (expected).
} dtstamp_t;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(sizeof(dtstamp_t));
}
void loop()
{
}