Suppose I have class with no data:
struct Empty {
/*some methods here*/
};
And a derived class
struct Derived: Empty {
int a;
int b;
char c;
....
}__attribute__((packed));`
Objects of Empty class have size = 1. Empty part of derived class usually has 0 size. As I understand compiler see that base Empty class has no data so it can optimize size of Empty in case it is "inside" Derived but it is not required to do it by the standard.
So the question is:
Can I somehow determine at compile time that Empty part of Derived class doesn't really occupy memory.
I understand that I can do check like sizeof(Derived) = sizeof(a) + sizeof(b) ...
But It is too verbose and there are several classes like Derived. Is there more elegant solution?