incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: question about aligned_storage
Date Thu, 26 Jun 2008 16:03:55 GMT
Travis Vitek wrote:
>  
> 
> Martin Sebor wrote:
[...]
>> 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.

An upper limit is acceptable (it should be mentioned in one of
the appendices to the spec). I'm more interested in alignments
that aren't powers of 2. It's not clear to me why restricting
the template to powers of 2 is okay or why it's difficult not
to support all of them up to the 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.

That's probably because they didn't want to favor any existing
implementation over others.

> 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.

That's what you for using a crappy compiler ;-) It compiles
with gcc. See
   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19163

but watch out for:
   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36625

We should open an enhancement request with Microsoft.

Martin

> 
>   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;
>   };
> 
> Travis
> 
>> Martin
>>
>>>> See http://tinyurl.com/5kmvdy for reference.
>>>>
>>>> Martin
>>>>
>>>>
>>


Mime
View raw message