www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/06/01:23:47

To: bob AT xnet DOT com, djgpp AT sun DOT soe DOT clarkson DOT edu
From: antony AT werple DOT mira DOT net DOT au (Antony Suter)
Subject: Re: Int's need to be on paragraph boundaries?
Date: Sat, 06 May 1995 13:37:24 -0400
Reply-To: antony AT werple DOT mira DOT net DOT au
Lines: 30

>i'm having an interesting problem.  i have the following struct that i am
>reading in from a file:
>
>char attrib;
>unsigned short int numkeys;
>unsigned long left;
>unsigned long right;
>char continue;
>char *keys;
>
>the file physically reads as follows:
>
>hex: "01  F0 00  00 00 00 00  00 00 00 00  00  00 06 00 00  30 32 . . ."
>
>somehow a byte is getting lost, and it doesn't make much sense.  i could
>understand possibly some of the values being screwy because of the uneven
>offset of the int, but the entire structure being offset and a byte lost?

Your problem must be structure element padding. I think the compiler
is by default adding a pad byte after 'attrib' before 'numkeys'. When you
read the data from the file, you cant see the 2nd byte cause it landed in
the pad byte.

For info on structure padding, see the notes that went through this list
3 days ago, or maybe look in the FAQ.

--
- Antony Suter  <antony AT werple DOT mira DOT net DOT au>
- (Rohaan)      <s871780 AT minyos DOT xx DOT rmit DOT edu DOT au>
- "In space, all warriors are Code warriors", Chang, ST6

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019