Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Why in C++, Empty structure has size 1 byte and In C, 0 byte? (http://www.go4expert.com/forums/cpp-empty-structure-size-1-byte-c-0-byte-t16563/)

imrantechi 17Mar2009 14:32

Why in C++, Empty structure has size 1 byte and In C, 0 byte?
 
In C++ , size of empty structure is 1 byte where in C, size of structure is zero?

As per my knowledge, If you will take array of n objects of any structure then where there distinguish so they have taken size atleast one byte, But this rule should apply to same in C also. Can you give me some proper answer?

asadullah.ansari 17Mar2009 15:46

Re: Why in C++, Empty structure has size 1 byte and In C, 0 byte?
 
When structure is introduced in C, that time there is no concept of Object. So C standard commette(C99) decided to keep zero size of empty structure.

In C++, Size of empty structure/class will be one byte bcoz.

struct Test
{
public:
void Disp( void );
};

int main()
{
Test tObj;
tObj.Disp();
return 0;
}
To call function atleast empty structure should have some size i.e. one byte. But there is no concept of member function in structure in C.


All times are GMT +5.5. The time now is 03:00.