Is 'sizeof' evaluated at compile time or run time? If it's at compile time, why doesn't this compile with VC8..?
Code:
__declspec(align(sizeof(int))) struct s {
char a;
int b, c;
};
"Compile time" doesn't automatically mean whatever you can do in C++ at compile time, you can stick the value into something that is a Microsoft extension.
The sizeof() is not part of the C++ preprocessor -- the phase of compilation where sizeof() is determined is done after preprocessing and more than likely after the Microsoft extensions are established. It is no more different than doing something like this:
Code:
template <int N>
struct Factorial
{
enum { value = N * Factorial<N-1>::value };
};
template <>
struct Factorial<1>
{
enum { value = 1 };
};
__declspec(align(Factorial<2>)) struct s {
char a;
int b, c;
Does this compile? I would think that it doesn't, even though the answer for Factorial<2> is generated at compile time.
Bookmarks