delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/10/04/22:32:10

From: johnson AT cdsmn DOT mn DOT org (Erik Johnson)
Subject: how do you pack structs?
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Mon, 4 Oct 93 12:46:58 CDT

Is it possible to pack a struct, so that it uses the least amount of memory
required for the data.

example:
struct {
    uchar reg;
    uchar *scr;
    uchar r,g,b;
} RGB;

Normally sizeof(RGB)==12.  Is it possible to tell the compiler NOT to pad out
structs to multiple-of-4 sizes.  I understand that in the above example,
swapping reg and scr would result in a sizeof()==8 (which is what I want),
but when you are working with file headers that are not of your own design,
you can not simply reorder your struct.

Thank you,


Erik R Johnson



- Raw text -


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