sizeof struct between ATmega328 and ESP8266

Hi! compiled for an ArduinoUno this struct has a size of 3 byte:

struct SensorData {
    signed int temp : 12;
  unsigned int ldr  : 10;
  unsigned int bad  : 1;
};

When compiled for ESP8266, it has a size of 4 byte. Even with this modification:

struct SensorData {
  int16_t  temp : 12;
  uint16_t ldr  : 10;
  uint8_t  bad  : 1;
};

What can I do, to have it three byte long on ESP8266 ?

Thanks in advance, Detlev

You could maybe try packing pragmas, but why is it important?

What can I do, to have it three byte long on ESP8266 ?

Probably nothing. The bit count information is a suggestion to the compiler, not a requirement that it must implement.

Get rid of that, and live with a 4 byte struct on both platforms.

It would result in 24*60=1440 unused byte in RAM and it also would need a more complex function for sending the entire array to a python-script (which expects a single sensordata in a length of three byte).

So, do the packing yourself.

It would result in 24*60=1440 unused byte in RAM

That implies that you are using more than 4320 bytes of SRAM on the Uno. How is THAT possible?

PaulS: That implies that you are using more than 4320 bytes of SRAM on the Uno. How is THAT possible?

On the Arduino, this data resides on two EEPROMs. 4KB in AT24C32 and 1KB inside of the ATmega328.

struct SensorData { ... } __attribute__((packed));

oqibidipo: struct SensorData { ... } __attribute__((packed));

That works! Thanks :-)

I think packing will make access to your array of structures less efficient for the ESP8266. This is because members of some array elements will likely span 32-bit word boundaries. But, if memory use is more important in your application than processor cycles, then it should be OK.