delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/22/21:45:46

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Struct with array. HELP
Date: Wed, 22 Apr 1998 19:15:36 +0100
Organization: None
Distribution: inet
Message-ID: <POfkpDAIPjP1EwFh@talula.demon.co.uk>
References: <6hi61a$avd1 AT willy DOT cra DOT enel DOT it> <6hk0t8$avd2 AT willy DOT cra DOT enel DOT it>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 20
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>I've read the faq again and I've found the solution:
>
> char x[n] __attribute__ ((packed));

That will indeed force your structures to be packed, but before you just
jump into doing this, ask yourself whether it is really needed. The
compiler adds this padding for a good reason: it makes things much
faster. I think that in 99% of cases, it is better to change your code
than to force a structure to be packed. The usual reason for needing
this is when you are doing block reads from some disk file format, but
it is IMHO much better to implement such things as a series of calls to
read individual bytes, words, and dwords. At minimum performance
overhead, that insulates you from any changes in structure padding, data
type sizes, and endianess, and in the long run it will make your code
much more portable and robust.


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa

- Raw text -


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