In this case, your class is POD, so you can use the offsetof
macro from <cstddef>
.
In practice, in most implementations, for most classes, you can use the same trick which offsetof typically uses:
int offset = &(((object *)0)->c) - (object *)0;
No need to actually create an object, although you may have to fight off some compiler warnings because this is not guaranteed to work.
Beware also that if your class has any multiple inheritance, then for (at least) all but one base, (void*)(base*)some_object != (void*)(derived*)some_object
. So you have to be careful what you apply the offset to. As long as you calculate and apply it relative to a pointer to the class that actually defines the field (that is, don't try to work out the offset of a base class field from a derived class pointer) you'll almost certainly be fine. There are no guarantees about object layout, but most implementations do it the obvious way.
Technically for any non-POD class, it does not make sense to talk about "the offset" of a field from the base pointer. The difference between the pointers is not required to be the same for all objects of that class.