Reputation: 1687
In C++11 can I use alignof on non-static data members without an object?
If i have a class, for example
class A
{
int num;
unsigned char letter;
};
can I use alignof(A::letter);
similarly to the extended sizeof syntax (e.g sizeof(A::letter);
)?
Upvotes: 3
Views: 450
Reputation: 88215
Yes. The changes that allowed this for sizeof also apply to alignof. Here's one of the papers that propose the changes for sizeof. Basically it's done by changing the meaning of unevaluated operands, and alignof uses an unevaluated operand.
Trying it in a compiler that claims to support alignof, Clang (top of trunk), worked for me.
Upvotes: 4