Possible Duplicates:
Empty class in C++
What is the size of an empty struct in C?
I read somewhere that size of an empty struct in C++ is 1. So I thought of verifying it.
Unfortunately I saved it as a C file and used <stdio.h>
header and I was surprised to see the output. It was 0.
That means
struct Empty {
};
int main(void)
{
printf("%d",(int)sizeof(Empty));
}
was printing 0
when compiled as a C file and 1
when compiled as a C++ file. I want to know the reason. I read that sizeof
empty struct in C++ is not zero because if the size were 0
then two objects of the class would have the same address which is not possible. Where am I wrong?
C
. – Clemenceau