__alignof__(T) not compile time constant?

Jamie Lokier jamie@shareable.org
Fri Oct 3 06:15:00 GMT 2003


Paolo Carlini wrote:
> Can you imagine a temporary fix for libstdc++/8670? Perhaps that
> suggested at the time by Martin?

In principle this ought to work, although it doesn't seem to (forgive
me if this isn't a good way to write it, it's 6 years since I wrote C++):

template <int a> struct aligned;

struct aligned<1> { template <typename _t> struct t { typedef __attribute__((aligned(1))) _t type; }; };
struct aligned<2> { template <typename _t> struct t { typedef __attribute__((aligned(2))) _t type; }; };
struct aligned<4> { template <typename _t> struct t { typedef __attribute__((aligned(4))) _t type; }; };
struct aligned<8> { template <typename _t> struct t { typedef __attribute__((aligned(8))) _t type; }; };
struct aligned<16> { template <typename _t> struct t { typedef __attribute__((aligned(16))) _t type; }; };

struct foo {
  aligned<__alignof__(long long)>::t<char>::type x;
} bar;

-- Jamie



More information about the Gcc mailing list