delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/09/02:27:49

Date: Mon, 8 Aug 94 10:52:44 CDT
From: leroy AT norland DOT com (Todd LeRoy)
To: uunet!cae.wisc.edu!pochanay AT uunet DOT uu DOT net
Subject: Re: How do I ...?
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

You ask:

2)  How do I get DJGPP not to pad a structure like this:

struct {
    SHORT  a;
    LONG   b;
    SHORT  c;
       }

    It seems to throw a two byte pad between a and b -- this is kinda
    annoying because a lot of graphics files have structures that are
    read that are like this with no padding.  (i.e. MicroSoft .BMP)

Answer (at least one possible answer - there may be others):

struct {
    SHORT  a __attribute__((packed));
    LONG   b __attribute__((packed));
    SHORT  c __attribute__((packed));
       }
I just went through this on Friday, so your timing ws perfect.    If you find
an easier way, I'd appreciate knowing about it.  I also need to R/W existing
file structures, and adding this to EVERY line of a struct will be kind of
annoying.  I tried applying the attribute to the entire struct, but that 
prevents entire structs from being padded, not the elements therein.

Good luck,

Todd LeRoy
E-Mail:  leroy AT norland DOT com
PHONE:   (414) 563-8456 ext. 354
US Mail: Todd LeRoy, Norland Corp., W6340 Hackbarth Rd, Fort Atkinson, WI 53538

- Raw text -


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