Mail Archives: djgpp/1997/04/08/07:16:21
Date: | Tue, 8 Apr 1997 14:00:58 +0300 (EEST)
|
From: | "Adrian Gh. Oboroc aka AsH / DEVOTiON" <oboroc AT usm DOT md>
|
To: | Mark T Logan <fwec AT juno DOT com>
|
Cc: | djgpp AT delorie DOT com
|
Subject: | Re: Problem with Packed structs
|
In-Reply-To: | <19970407.211716.7135.3.fwec@juno.com>
|
Message-Id: | <Pine.BSF.3.95q.970408134721.6436E-100000@usm.md>
|
Mime-Version: | 1.0
|
On Mon, 7 Apr 1997, Mark T Logan wrote:
> I have a slight problem with the way that DJGPP packs its structs.
> I am working on a project that saves its files as X number of structs,
> in a binary file.
You might want to use '#pragma pack' method:
#pragma pack(1)
struct Heroin
{
char dealer[100];
int quality;
double weight;
}
#pragma pack()
but guys from FSF, who develops GCC, don't like pragmas, thus you'll get
some warnings at compilation stage.
Also you might want to use 'attribute packed' method (sorry, I can't
provide example, because now I don't remember details, but you may find
more info in DJGPP FAQ). This method don't produce warnings, but as far as
I heared it does not have any effect in C++ code. And also this method is
unknown to non GNU C and C++ compilers (Watcom or Borland for example).
But IMHO the best method is to read and write each element of structure
separatly. This is how realised pcx & lbm loaders in Allegro. The bad side
of this method is that it requires more lines of source code. The good
thing is that it works *ON ANY* compiler, and no matter wich internal
representation your structures have.
Greets, Adrian
- Raw text -