What is the value of sizeof(Int_t)?

I’m using ROOT&C++ to read data from a binary data file created by Fortran program. We know that the format of Fortran binary data file is:

[size in byte of the record#1]
[record#1]
[size in byte of the record #1]
[size in byte of the record #2]
[record #2]
[size in byte of the record #2]

So, afer in.open(datafilename, ios::binary | ios::in), I use in.read((char*) n, sizeof(Int_t)) to read in the size of record #1. Where, n is an Int_t.

Well, I’m having inconsistant results from the ROOT on my Mac and my Linux box.

I suppose sizeof(Int_t) is a fixed number, 4, on any platforms — that’s the original idea to have Int_t, right?

Why is this inconsistance happening? Thanks!

well, a simple test tells me the sizeof(Int_t) is 4. :slight_smile: Sorry for the confusion.

But what make my program read in wrong numbers on Linux?

Int_t size_lead, sys, size_tail;

in.read((char*)&size_lead, sizeof(Int_t));
in.read((char*)&sys, sizeof(Int_t));
in.read((char*)&size_tail, sizeof(Int_t));

Here, size_lead and size_tail should have the same number, i.e. the length of the record, which is 4, an interger. And 39 is the right number for sys in my data file.

This code reads in right numbers on Mac OS X but not on Linux after I copied the program and the binary data file over.

Thanks for you time!

Very likely you are facing a byte swapping problem.
The MAC and Intel platforms have different types representation.
If your data have been written on a MAC, you must do the byte swapping
for all types greater than 1 byte.
This is one of the tasks that ROOT is doing for you when writing and
reading with ROOT.

Rene

Yeah, it’s the byte arrangement problem, so called NUXI problem, due to different endian conventions.

Thanks for helping!