Mail Archives: djgpp/1995/07/23/01:13:25
mictali AT netcom DOT com (Jere McDevitt) writes:
>Simply put, I have a program that uses a structure with a LONG variable. I
>set the variable to a value in a DJGPP compiled application and write the
>structure to a file. When I read the same structure back in using a Dos
>application (16 bit ) compiled with Borlandc 3.1 (variable sizes match -
>used short not int) then the byte order of the LONG variable is reversed.
>What was written out as 0x00000084 comes in as 0x84000000.
This is probably not a problem with byte ordering but with structure
padding. GCC, more than a lot of other compilers and padding bytes
between elements of a structure. It does this to make sure the access
to the members is always on a boundry that will allow the fastest
access.
To test that this is the case, make a small program that declares one
of these structures and the prints the structure
(printf("%d\n",sizeof(struct theStruct))). I bet that the Borland and
GCC will print different numbers.
GCC does provide a __packed__ attribute that allows structure members
to be packed together if possible, and probably give youthe same
format that Borland would.
--
Andrew Langmead
- Raw text -