incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <>
Subject RE: question about aligned_storage
Date Wed, 25 Jun 2008 17:11:59 GMT

Martin Sebor wrote:
>Travis Vitek wrote:
>> Martin Sebor wrote:
>>> While looking at the hoops we jump through to implement 
>>> aligned_storage
>>> I recalled the gcc __attribute__ (aligned (N)). Is there 
>>> any to use it to simplify the implementation for gcc?
>> We already do.
>You're a step (or a few) ahead of me, as usual... :)

You give me more credit than I deserve. I'm making this stuff up as I
go... :)

>> Have a look at the definition of the macro
>You mean the one in rw/_gcc-config.h on the 103 character long line?
>(You almost got away with it ;-)

Yeah, I have a few long lines. I need to clean up the mess that I've

>> I might be able to eliminate __rw_aligned_storage_impl<> if 
>> I wanted to
>> do a partial specialization of __rw_aligned_storage<> on the _Align
>> non-type template parameter and I could also eliminate
>> __rw_default_alignment<>, but that is about as much as I 
>> think I could reduce it.
>I'm probably missing something but is aligned_storage only specified
>for alignment of powers of 2? (It looks to me as though those are the
>only alignments we support.)

Yes. I probably need to do something here, but I'm not sure what. Table
51 says

  _Align shall be equal to alignment_of<T>::value for some type
  T or to `default-alignment'

This essentially says that I need to support all valid alignment values
on the platform. Fortunately, for the time being the power of two
restriction is okay. The only functionality I have available to me for
doing alignment (on the tested platforms) is __declspec(align(#)) on
Microsoft and __attribute__ ((aligned(#))) on gcc-4.3. Both of these
support functions require that the alignment value be a power of two.
The Microsoft compiler has the 8192 limit.

The draft shows a 'typical implementation' of aligned_storage that uses
the new alignas keyword, but alignas doesn't appear to be supported
anywhere. The following code is very similar to that typical
implementation, but it does not compile because value passed to the
aligned attribute has to be a literal, not a constant expression.

  template <std::size_t _Size,
            std::size_t _Align = __rw_default_alignment<_Size>::value>
  struct __rw_aligned_storage
      typedef struct {
          char _C_align [_Size] __attribute__ ((aligned(_Align)));
      } type;


>>> See for reference.
>>> Martin

View raw message