Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-03-07 10:13:37

"Martin Bonner" <martin.bonner_at_[hidden]> wrote in message
> ----Original Message----
> From: Emile Cormier
>> The bitfield mechanism relies on this assumption: Unions of
>> non-polymorphic, non-derived objects, having the exact same underlying
>> data member type, will have the same size as this underlying data
>> member type. I'm no language lawyer, so please let me know if this is
>> a safe and portable assumption.
> I'm not quite sure what you mean, but given:
> struct a { unsigned char ch; };
> struct b { unsigned char ch; };
> union u { a theA; b theB };
> then you are not guaranteed that sizeof(u) == sizeof(unsigned char).

Though in practise you can use:

BOOST_STATIC_ASSERT(sizeof(u) == sizeof(unsigned char))

> On word addressed machines (which /are/ still being built), it is almost
> certain that the minimum size for a struct is a complete word. This is
> because the C and C++ standards effectively promise that pointers to
> structs are all of the same size (the size of a pointer-to-struct does
> not depend on the contents of the struct). It is desirable that a
> pointer-to-struct be the smaller, cheaper-to-dereference pointer to word
> (rather than the larger more-expensive-to-dereference pointer to char),
> so the smallest struct has to occupy a whole word.

I dont see why the size of a pointer to a struct affects the size of a struct
which in the case of an empty struct is often 1 byte?

Andy Little

Boost list run by bdawes at, gregod at, cpdaniel at, john at