From: Richard Nichols Newsgroups: comp.os.msdos.djgpp Subject: Re: packed? Date: Fri, 09 Jan 1998 19:15:31 +1000 Organization: None Lines: 40 Message-ID: <34B5EAB3.4E6E@mailhost.net> References: <34B5D88E DOT A5F81932 AT xmission DOT com> Reply-To: tiberius AT mailhost DOT net NNTP-Posting-Host: 138.77.56.32 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk David Eberhard wrote: > > I have been going over some source code for a linear-frame buffer and > in the source code, the author used some attribute called pack. What > is this? Here's some of the code: > > #define PACKED __attribute__ ((packed)) > #pragma pack(1) > /* SuperVGA mode information block */ > typedef struct { > short ModeAttributes PACKED; // Mode attributes > char WinAAttributes PACKED; // Window A attributes > --snip-- > #pragma pack() > this tells the compiler not to align the data to dword boundaries otherwise the above would be in RAM: typedef struct { short ModeAttributes PACKED; // Mode attributes (2 bytes padding) char WinAAttributes PACKED; // Window A attributes (3 bytes padding) and when a int returns data in the struct you don't want any bytes in the way which aren't supposed to be there. This can of course make your program a little slower.. -Rich -- .------------------------------+--------------------------------. | Richard Nichols | Inspire Media (Demos/Games) | | mailto:tiberius AT mailhost DOT net | mailto:InspireMedia AT post1 DOT com | | http://tiberius.home.ml.org/ | http://inspire.home.ml.org/ | +------------------------------+--------------------------------+ | Organizer, coder for Inspire Media | `---------------------------------------------------------------' "The life of the coder is that of the hermit, except the hermit can't make shadebobs." -- Leviathan