Skip to main content
deleted 4 characters in body; edited title
Source Link

sizeof tm struct (datetime) different on arduinoESP32 vs linux64x

I am logging binary data to my SD. I log a datetime object of type 'tm', which is 36 bytes on arduinoESP32. When I create a datetime of type 'tm' on linux it is 56 bytes.

ArduinoESP32 write tm to SD: [tm datetime = 36 bytes]

time_t t = std::time(nullptr);
tm datetime = *std::localtime(&t);
uint16_t t = file.write((const uint8_t *)&datetime, sizeof(datetime)); // ==36 bytes.

PC [tm datetime = 56 bytes] (compiled using g++ on linux 64)

tm datetime;
std::ifstream fileStream(filename, std::ios::binary);
fileStream.read((char *)&datetime, sizeof(datetime));

tm is defined in time.h:

struct tm
{
  int   tm_sec;
  int   tm_min;
  int   tm_hour;
  int   tm_mday;
  int   tm_mon;
  int   tm_year;
  int   tm_wday;
  int   tm_yday;
  int   tm_isdst;
#ifdef __TM_GMTOFF
  long  __TM_GMTOFF;
#endif
#ifdef __TM_ZONE
  const char *__TM_ZONE;
#endif
};

My tm struct doesn't have the 'tm_gmtoff' or 'tm_zone', even if it had it wont add up to 56 bytes.

How can my tm be 56 bytes on my PC? If someone has a better way to log a datetime object, without this issue, let me know.

sizeof tm struct (datetime) different on arduino vs linux64x

I am logging binary data to my SD. I log a datetime object of type 'tm', which is 36 bytes on arduino. When I create a datetime of type 'tm' on linux it is 56 bytes.

Arduino write tm to SD: [tm datetime = 36 bytes]

time_t t = std::time(nullptr);
tm datetime = *std::localtime(&t);
uint16_t t = file.write((const uint8_t *)&datetime, sizeof(datetime)); // ==36 bytes.

PC [tm datetime = 56 bytes] (compiled using g++ on linux 64)

tm datetime;
std::ifstream fileStream(filename, std::ios::binary);
fileStream.read((char *)&datetime, sizeof(datetime));

tm is defined in time.h:

struct tm
{
  int   tm_sec;
  int   tm_min;
  int   tm_hour;
  int   tm_mday;
  int   tm_mon;
  int   tm_year;
  int   tm_wday;
  int   tm_yday;
  int   tm_isdst;
#ifdef __TM_GMTOFF
  long  __TM_GMTOFF;
#endif
#ifdef __TM_ZONE
  const char *__TM_ZONE;
#endif
};

My tm struct doesn't have the 'tm_gmtoff' or 'tm_zone', even if it had it wont add up to 56 bytes.

How can my tm be 56 bytes on my PC? If someone has a better way to log a datetime object, without this issue, let me know.

sizeof tm struct (datetime) different on ESP32 vs linux64x

I am logging binary data to my SD. I log a datetime object of type 'tm', which is 36 bytes on ESP32. When I create a datetime of type 'tm' on linux it is 56 bytes.

ESP32 write tm to SD: [tm datetime = 36 bytes]

time_t t = std::time(nullptr);
tm datetime = *std::localtime(&t);
uint16_t t = file.write((const uint8_t *)&datetime, sizeof(datetime)); // ==36 bytes.

PC [tm datetime = 56 bytes] (compiled using g++ on linux 64)

tm datetime;
std::ifstream fileStream(filename, std::ios::binary);
fileStream.read((char *)&datetime, sizeof(datetime));

tm is defined in time.h:

struct tm
{
  int   tm_sec;
  int   tm_min;
  int   tm_hour;
  int   tm_mday;
  int   tm_mon;
  int   tm_year;
  int   tm_wday;
  int   tm_yday;
  int   tm_isdst;
#ifdef __TM_GMTOFF
  long  __TM_GMTOFF;
#endif
#ifdef __TM_ZONE
  const char *__TM_ZONE;
#endif
};

My tm struct doesn't have the 'tm_gmtoff' or 'tm_zone', even if it had it wont add up to 56 bytes.

How can my tm be 56 bytes on my PC? If someone has a better way to log a datetime object, without this issue, let me know.

Source Link

sizeof tm struct (datetime) different on arduino vs linux64x

I am logging binary data to my SD. I log a datetime object of type 'tm', which is 36 bytes on arduino. When I create a datetime of type 'tm' on linux it is 56 bytes.

Arduino write tm to SD: [tm datetime = 36 bytes]

time_t t = std::time(nullptr);
tm datetime = *std::localtime(&t);
uint16_t t = file.write((const uint8_t *)&datetime, sizeof(datetime)); // ==36 bytes.

PC [tm datetime = 56 bytes] (compiled using g++ on linux 64)

tm datetime;
std::ifstream fileStream(filename, std::ios::binary);
fileStream.read((char *)&datetime, sizeof(datetime));

tm is defined in time.h:

struct tm
{
  int   tm_sec;
  int   tm_min;
  int   tm_hour;
  int   tm_mday;
  int   tm_mon;
  int   tm_year;
  int   tm_wday;
  int   tm_yday;
  int   tm_isdst;
#ifdef __TM_GMTOFF
  long  __TM_GMTOFF;
#endif
#ifdef __TM_ZONE
  const char *__TM_ZONE;
#endif
};

My tm struct doesn't have the 'tm_gmtoff' or 'tm_zone', even if it had it wont add up to 56 bytes.

How can my tm be 56 bytes on my PC? If someone has a better way to log a datetime object, without this issue, let me know.