Boost logo

Boost :

From: Maxim Yegorushkin (e-maxim_at_[hidden])
Date: 2004-08-08 03:21:50


Maxim Yegorushkin <e-maxim_at_[hidden]> wrote:

> I am using boost::aligned_storage<> and I would like it to be aligned on 32 byte boundary (the reason being that sizeof(my type) is 32 bytes and I want it to be aligned on x86 cash line size so that it is cashed most effectively). I am working now under VC7.1 and it seems like the maximum alignment I can get with the compiler is 8 which is the alignment of the largest built-in type which is long double (or a pointer to member/function). But type_with_alignment.hpp seems to have special support for gcc in the form of:
>
> namespace align {
> struct __attribute__((__aligned__(2))) a2 {};
> struct __attribute__((__aligned__(4))) a4 {};
> struct __attribute__((__aligned__(8))) a8 {};
> struct __attribute__((__aligned__(16))) a16 {};
> struct __attribute__((__aligned__(32))) a32 {};
> }
>
> template<> class type_with_alignment<1> { public: typedef char type; };
> template<> class type_with_alignment<2> { public: typedef align::a2 type; };
> template<> class type_with_alignment<4> { public: typedef align::a4 type; };
> template<> class type_with_alignment<8> { public: typedef align::a8 type; };
> template<> class type_with_alignment<16> { public: typedef align::a16 type; };
> template<> class type_with_alignment<32> { public: typedef align::a32 type; };
>
> Are MSVSs going to be supported as they have similar extension __declspec(align(x))?

I've just found out that the following code won't compile on MSVC7.1:

     struct some
     {
         struct __declspec(align(32)) align {};
         align a;
     };

     void f(some s); // error C2719: 's': formal parameter with __declspec(align('32')) won't be aligned

     int main()
     {
         some s;
         f(s);
     }

Was that the reason for not adding __declspec(align(x)) support for MSVC?

I also found that Intel C++ 8 compiles the code without a complain, though it's unclear what effect __declspec(align(x)) has on the compiler.

-- 
Maxim Yegorushkin

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