# Size of a non-static member of a class

How to get the size of a non-static member of a class without construct that class?

## C

[sizeof operator](https://en.cppreference.com/w/cpp/language/sizeof):

> When applied to an expression, sizeof does not evaluate the expression...

Hence, we can write:

```cpp
sizeof(((Foo*) 0)->m);
```

## C++

`c++0x` allow that:

```cpp
// a more elegant way
sizeof(Foo::m);
```

[expr.prim.id.qual](https://timsong-cpp.github.io/cppwp/n4659/expr.prim.id.qual#2):

> A nested-name-specifier that denotes a class, optionally followed by the keyword template ([temp.names]), and then followed by the name of a member of either that class ([class.mem]) or one of its base classes, is a qualified-id; ... The result is an lvalue if the member is a static member function or a data member and a prvalue otherwise.

## Reference

[Extending sizeof to apply to non-static data members without an object (revision 1)](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2253.html)

[Getting the size of member variable](https://stackoverflow.com/questions/5976879/getting-the-size-of-member-variable)
