Fixed point structure size

Hi, 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? Soren

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.
participants (2)
-
Phil Endecott
-
Soren Holstebroe