Comments on: Size of an Empty Struct? /sizeof-empty-struct A Developers Diary Sun, 18 Dec 2011 15:21:56 +0000 hourly 1 https://wordpress.org/?v=6.8.1 By: Sunil Manikani /sizeof-empty-struct/comment-page-1#comment-3222 Sun, 18 Dec 2011 15:21:56 +0000 /sizeof-empty-struct.html#comment-3222 From the website of creator of c++; I found that this discussion can be more useful when we take into account inheriting from empty classes…
______________________________________________________________________________

class Empty { };

void f()
{
Empty a, b;
if (&a == &b) cout << "impossible: report error to compiler supplier";

Empty* p1 = new Empty;
Empty* p2 = new Empty;
if (p1 == p2) cout <a;
if (p1 == p2) cout << "nice: good optimizer";
}

This optimization is safe and can be most useful. It allows a programmer to use empty classes to represent very simple concepts without overhead. Some current compilers provide this "empty base class optimization".

regards,
Sunil.

]]>