delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/30/12:18:03

From: ams AT ludd DOT luth DOT se (Martin Str|mberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: -fpack-struct
Date: 29 May 1999 23:30:50 GMT
Organization: University of Lulea, Sweden
Message-ID: <7iptba$jik$2@news.luth.se>
References: <l03130300b375f8976547@[145.98.116.66]>
NNTP-Posting-Host: queeg.ludd.luth.se
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
Lines: 34
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Dlanor Blytkerchan (dlanor AT dds DOT nl) wrote:
: I have a small problem with getting my code to be compatible with some
: other code I did not write. The problem is this: The code I did not write
: was written in basic (QBX/PDS) and uses a TYPE definition (like "struct" in
: C) of 107 bytes. This TYPE has two strings in it, one of which has a size
: of three bytes. If I make the same TYPE in C like this:
: typedef struct {
:   (..)
: } myStructure;
: it is 108 bytes: there is an extra byte, as the struct members are
: word-aligned. This is exactly the problem: getting it to be byte-aligned to
: get it compatible with the basic code (as Basic reads/writes 107 bytes per
: DB record to disk, and C reads/writes 108 bytes). Looking it up in the
: compiler options, I found the option "-fpack-struct" that should do what I
: want it to do: byte-align the structs. My problem is this: the gcc info
: file says: "the offsets of the structure members won't agree with system
: libraries". This is what worries me: what does this mean and how likely is
: it that this will cause problems? If it is likely to cause problems, is
: there another way to byte-align the struct that won't cause problems, or
: should I write I/O code that cuts the struct in pieces when reading/writing
: it to files?

This is how I would attack the problem-

Step 1.  Figure out the byte sequence. You need to know what bytes is
         where in your data type.

Step 2.  When you know this, you can memcpy() the data you need to
         the data types that you have defined. 


Alanis Morissette, Supposed Former Infatuation Junkie,

							MartinS

- Raw text -


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