Mail Archives: djgpp/1998/01/09/04:31:55
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
- Raw text -