Boost logo

Boost :

Subject: Re: [boost] How do I specify no padding bytes within a struct/class?
From: Jason Roehm (jasonr_at_[hidden])
Date: 2013-06-17 12:43:26


On 06/17/2013 12:41 PM, Daryle Walker wrote:
> I've never done this before, so I'm asking first: how do I specify that a
> struct/class should have no padding at all, at the start, end, or middle?
> My classes have internal arrays, and specifying no padding lets users use an
> array of classX<T> as an array of T (just like C++11 std::complex).
> Complier-specific answers are OK, as long as I can use preprocessor flags to
> isolate them.
>
> I have a preprocessor flag that's currently set to 0 to indicate that
> there's no packing. I'll change it to 1 whenever I get a compiler's packing
> support.

This will always be compiler-specific. For gcc, try the
__attribute__((packed)) directive, documented here:

     http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html

Jason


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk