sizeof (struct) differs from Windows and Linux. How can I fix this?



I store data of several large arrays of structs in a binairy file. There are 2 kinds of structs:
Struct 1 has 3 x gchar[70] and 16 doubles and one guint[12].
Struct 2 has 2 x gchar[70] and 4 doubles.

On linux and Windows the following results are the same:
sizeof(double)=sizof(gdouble) = 8
sizeof(guint)=4
sizof(gchar)=1

So netto the size of struct1 should be : 386 and struct 2 172.

Now on Linux the size of the structs are resp. : 388 and 172.

And on Windows XP (cross-compile mingw on Linux): 392 and 176.

Now I don't mind that they are slightly bigger than the sum of their elements, but the problem is that I can not load the library in Windows (just ported that, loading on Linux is okay because the binairy file also saves them with size 388 and 172).

I have the following questions:
1) Should the struct be as large as their elements or does the definition of the struct itself needs some space (and if so, why not for the 172 byte - struct)?
2) How can I read the file in Windows correctly?

Because the sum of the elements on Linux and Windows is the same I have an idea that guint16 and its friends (always the same size) won't help me in my case. It's the struct that is different! (I think ...?)


Help is very much appreciated.
Edward Hage






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]