size of empty struct ?

C

cppfans

Why the size of an empty struct or class is 1?
i guess 4 before i run this programm.

for example:
compile with Dev C++

#include <stdio.h>
#include <stdlib.h>

typedef struct tagEMPTY
{} EMPTY,*PEMPTY;

class CEmpty
{};

int main()
{
EMPTY e;
CEmpty ce;
printf("%d,%d\n",sizeof(e),sizeof(ce));
printf("%d,%d\n",sizeof(EMPTY),sizeof(CEmpty));
system("PAUSE");
}
 
J

John Harrison

cppfans said:
Why the size of an empty struct or class is 1?
i guess 4 before i run this programm.

All the C++ standard says is that it is not zero. Both one and four seem
reasonable values and I'm sure you'd find that different compilers give
different results.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top