Mail Archives: djgpp/1995/05/03/23:25:29
Hi,
I've got a stuct like
typedef struct {
short id;
char fc[3];
short pos;
...
} trREC,*tpREC;
when I go to read the struct from a binary file the struct
appears to have padded a space between then end of fc and
start of pos. Is there a pragma to make sure the struct uses
the minimum amout of space?
I think this is a FAQ, see FAQxxx.ZIP at your SimTel mirror. Use
__attribute__ ((packed)). According to Info gcc, item variable
attributes:
typedef struct {
short id __attribute__ ((packed)); /* this is a no-op */
char fc[3] __attribute__ ((packed)); /* no padding after id */
short pos __attribute__ ((packed)); /* no padding after fc */
...
} trREC,*tpREC;
How much of a speed penalty will
I pay in the rest of the code (hav'ing non-word boundries)?
Would it be better skip the pragma and just to read the
fields one at a time?
IMHO, no. This use of __attribute__ documents the file structure in
the code.
--
Stephen Turnbull / Yaseppochi-gumi / <turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp>
http://turnbull.sk.tsukuba.ac.jp/ anon FTP: turnbull.sk.tsukuba.ac.jp
Check out Kansai-WWW, too ------------> http://pclsp2.kuicr.kyoto-u.ac.jp/
- Raw text -