Alex Rivera | Logout

What is the size of an empty struct in C?

Asked 2009-10-26T18:21:00.737
26

According to me, it is zero but there seems to be bit confusion here

I have tested it with gcc compiler and it gives me zero as output. I know that in C++, size of an empty class is 1. Let me know if I am missing anything here.

Edit
Report

1 Answer

1

on VC 8 It gives error if we try to get the sizeof empty struct, on the other way round on linux with gcc it gives size 1 because it uses gcc extention instead of c language specification which says this is undefined behaviour.

struct node
{
// empty struct.
};

int main()
{
printf("%d", sizeof(struct node));
return 0;
}

on windows vc 2005 It gives compilation error on linux with gcc it gives size 1 because gcc extension http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Empty-Structures.html#Empty-Structures (As Pointed out by Michael Burr)

answered 2013-06-04T12:37:04.707

Your Answer