Re: bool vs. BOOL




"MrAsm" <invalid@xxxxxxxxxxx> wrote in message
news:orprq2ppvdc9uk2q9f4lugr51efcabktei@xxxxxxxxxx


On Wed, 17 Jan 2007 07:12:53 -0000, "David Webber"
<dave@xxxxxxxxxxxxxxxxxxx> wrote:

As someone paranoid about structure packing and byte boundaries in
structures,

Dave: what is this?

Do you mean that if structures are 4-bytes aligned, the code is more
efficient (because PC architectures are 32 bits? But on 64 bits
machine?)

I probably really meant paranoid :-) It isn't really a question of
efficiency - more control-freakery :-)

I use bit fields a *lot*. If I need packing bit fields I put them in
explicitly so that bit fields do not cross 2 byte boundaries (or 1byte if I
can help it). I tend to set 2 byte boundaries for packing.

More generally, I do not like invisible packing bytes anywhere, and tend
always to put a "reserved" variable in so that I can see the whole structure
as it will be in memory (and zero unused elements explicitly in the
constructor). It is a habit I have got into.

There are some very good underlying reasons.

The main one is that my music software has large arrays of small
elements representing notes, bar-lines etc, and that in a new version these
may acquire more bit fields (in place of hitherto reserved ones) without
changing the size of the structure. They are read in as just so many bytes
from the data file, and when reading an old format file, I can do it in the
sure knowledge that the new bit fields will be read in as zero.

It is a paranoia which has served me well in code maintenance an development
over nearly two decades! :-)

The result is that I would never (in 32 bit systems) write

struct ...
{
BYTE ...
short ...
int ...
BYTE ....
};

but rather

struct ...
{
int ...
short ...
BYTE ...
BYTE ....
};

It just sort of offends my sense of what is right to do it the first way :-)

It might be like not walking under ladders, but I suspect we all have our
comfort zones :-)

Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm







.