www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/22/04:03:54

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allocation of memory.
Date: Mon, 21 Jul 1997 22:13:21 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 64
Message-ID: <33D3DF01.4A89@cs.com>
References: <33D210A6 DOT 5EDF AT lr DOT net> <33D28EF5 DOT 69F2 AT cs DOT com> <33D367F6 DOT 3E61 AT lr DOT net>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp105.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Isaac Waldron wrote:
> 
> struct PCXHeader
> {
>         char manufacturer;
>         char version;
>         char encoding;
>         char bpp;
>         int xStart, yStart;
>         int xEnd, yEnd;
>         int xRes, yRes;
>         char egaPal[48];
>         char reserved;
>         char numPlanes;
>         int bpl;
>         int pType;
>         char padding[58];
> };

DJGPP, as a 32-bit compiler, pads structure members to align them on 2
and 4 byte boundaries.  The above structure is 148 bytes in DJGPP; you
may be reading too many bytes from the PCX file to get the header
information!  Try using the __attribute__((packed)) gcc extension to
force the structure to take the minimum required space.  Also, I assume
you are aware that integers in DJGPP are 32 bits wide?  If you intend
those ints to be 16 bits, you must declare them as shorts.

Try this:

#define __PACK	__attribute__((packed))

struct PCXHeader
{
        char manufacturer __PACK;
        char version __PACK;
        char encoding __PACK;
        char bpp __PACK;
        short xStart, yStart __PACK;
        short xEnd, yEnd __PACK;
        short xRes, yRes __PACK;
        char egaPal[48] __PACK;
        char reserved __PACK;
        char numPlanes __PACK;
        short bpl __PACK;
        short pType __PACK;
        char padding[58] __PACK;
};

The new structure is 128 bytes long.

The most likely reason why this failed to work is that the wrong data
was being read into the xStart, yStart, xEnd, and yEnd members, and
bufsize was then calculated from this bad data.  To test, try printing
the value of bufsize after you calculate it.

hth!

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "History does not record anywhere at |
|       aka Fighteer I       | any time a religion that has any     |
|   mailto:fighteer AT cs DOT com   | rational basis."                     |
| http://www.cs.com/fighteer |                - Lazarus Long        |
---------------------------------------------------------------------

- Raw text -


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