The Size Of An Empty Object
Empty objects don't exist.


11 June 2014

Programmers’ theoretical minimum: the size of an empty object

class Empty { };
int main()
{
    Empty e;
    std::cout << "The size of e is " << sizeof(e);
}

Running this little program on my Macbook, I receive this output:

Running
The size of e is 1
Debugger stopped.
Program exited with status value:0.

In C++, empty objects don’t exist. Indeed, C++ allocate for the objects at minimum 1 bytes.

This is due to the fact that each object needs have a different address in memory.

##Further Information

C++11



blog comments powered by Disqus