Mail Archives: djgpp/1996/05/10/01:32:30
Gert-Jan Schoenmakers wrote:
> I've recently switch from Microsoft C/C++ 7.0 to djgpp 2.0 for
> developping signal processing software. Now I have a trouble reading
> binary data files which consist of a header and an amount of data. The
> recent discussion about the sizeof(int) was a first step in solving the
> problems I had (I redifined the int's to short int's) but now I'm stuck.
> The MSC compiled program tells me sizeof(struct header)=98 and the DJGPP
> compiled program tells me sizeof(struct header)=100.... Can someone help
> me out on this one ????
It's because ANSI C gives no specification on what kind of padding members of
structures will be given. That is to say, what you are attempting to do is
inherently nonportable. You should be reading in the members one at a time.
However, there are attributes to allow you to do this in gcc; there's a bug in
g++ 2.7.2 that won't even let this work; you'll need to use a #pragma. Check
the info file on gcc.
If you want your code to be at all portable (which it sounds like might not be
a bad idea, considering you're moving over from Microsoft to DJGPP), I
recommend against this method; read in the members one at a time.
--
Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com
San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
"Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
- Raw text -