|
Boost : |
Subject: Re: [boost] Fixed point structure size
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2009-06-25 18:01:13
Soren Holstebroe wrote:
> An important feature of the fixed point template is that it takes up
> no more space than the underlying integer.
> It should be possible to use reinterpret_cast to convert a third party
> integer pointer (representing fixed ints) to a fixed point template
> pointer.
>
> The way I ensure that in my fixed point template is with a #pragma:
> #pragma pack(push, 1)
> ... template struct ...
> #pragma pack(pop)
>
> This is supported by MSVC++ as well as gcc. However it is only defacto
> standard, so it might not work on any other compiler.
>
> Is there a more standard way to make sure that the struct is not
> padded to some memory alignment size?
assert(sizeof(fixed<N>)==expected_size)
- and let the user worry about what they need to add if the assertion fails.
In my (limited) experience, the only place where this would be a
problem is on the old ARM ABI where struct alignment is normally always
at least 4 bytes even if the struct only contains one byte. gcc's
__attribute__((packed)) fixes that.
Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk