Go Down

Topic: sizeof struct between ATmega328 and ESP8266 (Read 1 time) previous topic - next topic

dede67

Hi!
compiled for an ArduinoUno this struct has a size of 3 byte:
Code: [Select]
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:
Code: [Select]
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

AWOL

You could maybe try packing pragmas, but why is it important?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

dede67

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).

AWOL

"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

PaulS

Quote
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?
The art of getting good answers lies in asking good questions.

dede67

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.

oqibidipo

Code: [Select]
struct SensorData { ... } __attribute__((packed));
 

dede67

Code: [Select]
struct SensorData { ... } __attribute__((packed));
That works!
Thanks :-)

gfvalvo

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.

Go Up