delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/05/17:28:36

From: Bob <bob AT xnet DOT com>
Subject: Int's need to be on paragraph boundaries?
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Fri, 5 May 1995 14:51:22 -0500 (CDT)

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?

here is the [sorta] output from gdb on "display ...":
attrib = '\001', numkeys = 0, left = 0, right = 0,
continue = '\000', keys = "\006\000\00002 . . ."

the first four bytes in keys should read: "\000\006\000\000"

numkeys should really be 15 (F0 00)

i did a "display (char *) &keynode" and it said "\001\017" which is correct,
so the info is still there, but the structure is seeing it wrong.

am i doing something wrong?  actually, the fileread is to a buffer and then a
memcopy copies to the structure.  will either of these situations cause a
problem here?  i'd hate to reallign the structure [would screw up alot of
source code that works under borland].  if i need to redo the structure, is
there a way i can do it w/out screwing up compatibility w/ the borland version?
[ie maybe a bogus char in the structure ifdef'd to GNUC]

thanx for any info. [btw, im using 1.12m3]

confusedly,

bob
-- 
Robert Hollinger        <------------------------------------->
4B Chaucer Ln.          > \  www- http://www.xnet.com/~bob  / <  Disclaimer:
Streamwood, IL  60107   >   \/\/     bob AT xnet DOT com      \/\/   <
708-483-9391            <------------------------------------->I don't know her!
    Paul:  Hey Norm, how's the world been treating you?
    Norm:  Like a baby treats a diaper.

- Raw text -


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