Wrong size of struct


the code snippet below reveals the byte size of the struct (see also script attached)

  struct record_t {
    Int_t x;
    Int_t y;
    Int_t z;
  } rec;
  cout << "Record Length=" << sizeof(rec) << endl;

On my 32 bit linux machine I get the length = 12 when I compile the program. CINT however gives me 16. I figured that the size in CINT is always multiple of 8, although the size of the Int_t type is 4 bytes as it should be.

The discrepancy of the record length is particularly annoying when reading the same binary file both with a compiled and a CINT interpreted program. Is there a way to get the same record length for any simple struct?

Thanks in advance for your support,

reclen.C (277 Bytes)


The size of a struct or class is platform and compiler dependent.
So even if CINT was to decide to match its struct layout with your current compiler and platforms’ choice, this might not be true on a different platform.

However to have consistent behavior between what you have in the compiler and what you see in the interpreter, you simply have to compile the struct definition. (With this is simply adding a + when you load the file:
.L mystruct.h+)