Padding isn't part of a particular field, it's part of the struct itself. If I have a struct like
struct foo {
T1 v1;
// <--- some padding here (A)
T2 v2;
// <--- some padding here (B)
T3 v3;
};
Is the A padding part of v1? v2?. Is B part of v2? v3? If you are concerned about padding messing with doing things like persisting a struct to a file or similar, most (all?) compilers have a mechanism to disable structure padding, even on a struct by struct basis. To find out the size of the last member of your struct, in this case s
, use sizeof
, e.g.
struct a tmp;
size_t size = sizeof(tmp.s);
If you don't want to create a temporary you can take advantage of the fact that sizeof happens at compile time and doesn't do anything at runtime and do something like:
namespace {
const a& dummy_func();
}
size_t size = sizeof(dummy_func().s);
Dummy func doesn't need to be implemented ever.
Another option is
struct a {
...
typedef char s_type[255];
s_type s;
};
size_t size = sizeof(a::s_type);