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



Edward,

you might want to consider XDR as persistent binary format.

-Vlad

On Wed, 2004-12-29 at 12:57, edward hage wrote:
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



_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
-- 
_____________________________________________________________
Vladislav Grinchenko       http://home.comcast.net/~3rdshift/
                                 e-mail: 3rdshift comcast net
                                                   
      Focus on quality, and productivity will follow.
_____________________________________________________________




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