One question about size of empty class...
-
Dont bore of this 80's question...please excuse me for this... question is very simple... Why empty class's size is one Byte in C++??? Answer 1:suppose in case of creating array of objects of this empty class, then to distinguish them atleast 1 byte is required ... mE fedup of this answer My Doubt for this answer : If this reason is valid then why hell in C, empty structure's size is zero... Here also anyone can create the array of objects of this empty structure.Here no neeed to distinguise. Is It ???? Answer 2: Since in C++ provides function members so like class test { }; this is also empty class but by default every class has some default member's function... test tObject1=test(); test tObject2(tObject1); or class test { public: void fun(); }; test obj; obj.fun(); so to call this function it may required size atleast 1 byte... BUT I M NOT SUTE FOR WHAT REASON IN C++ THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C....PLEASE U CAN SHARE WHAT'S EXACT REASON????
Truth Can'nt be changed
-
Dont bore of this 80's question...please excuse me for this... question is very simple... Why empty class's size is one Byte in C++??? Answer 1:suppose in case of creating array of objects of this empty class, then to distinguish them atleast 1 byte is required ... mE fedup of this answer My Doubt for this answer : If this reason is valid then why hell in C, empty structure's size is zero... Here also anyone can create the array of objects of this empty structure.Here no neeed to distinguise. Is It ???? Answer 2: Since in C++ provides function members so like class test { }; this is also empty class but by default every class has some default member's function... test tObject1=test(); test tObject2(tObject1); or class test { public: void fun(); }; test obj; obj.fun(); so to call this function it may required size atleast 1 byte... BUT I M NOT SUTE FOR WHAT REASON IN C++ THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C....PLEASE U CAN SHARE WHAT'S EXACT REASON????
Truth Can'nt be changed
asadullah ansari wrote:
THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C
C++ != C and a C++ class is not a C struct the C++ standard requires that all class objects have a "nonzero size". see page 149 : http://www-d0.fnal.gov/~dladams/cxx_standard.pdf[^]
-
Dont bore of this 80's question...please excuse me for this... question is very simple... Why empty class's size is one Byte in C++??? Answer 1:suppose in case of creating array of objects of this empty class, then to distinguish them atleast 1 byte is required ... mE fedup of this answer My Doubt for this answer : If this reason is valid then why hell in C, empty structure's size is zero... Here also anyone can create the array of objects of this empty structure.Here no neeed to distinguise. Is It ???? Answer 2: Since in C++ provides function members so like class test { }; this is also empty class but by default every class has some default member's function... test tObject1=test(); test tObject2(tObject1); or class test { public: void fun(); }; test obj; obj.fun(); so to call this function it may required size atleast 1 byte... BUT I M NOT SUTE FOR WHAT REASON IN C++ THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C....PLEASE U CAN SHARE WHAT'S EXACT REASON????
Truth Can'nt be changed
that is what ++ in C++ means: add 1. :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
asadullah ansari wrote:
THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C
C++ != C and a C++ class is not a C struct the C++ standard requires that all class objects have a "nonzero size". see page 149 : http://www-d0.fnal.gov/~dladams/cxx_standard.pdf[^]
offcourse C != C++ ...Here offcourse C++ standard requires it so it's there But my question is why they have made like this... Some reason should be for this...
Truth Can'nt be changed
-
that is what ++ in C++ means: add 1. :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
reallly funny ...gud :laugh:
Truth Can'nt be changed
-
offcourse C != C++ ...Here offcourse C++ standard requires it so it's there But my question is why they have made like this... Some reason should be for this...
Truth Can'nt be changed
asadullah ansari wrote:
Some reason
because same pointers should imply same objects (and same types), different pointer values different objects. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
Dont bore of this 80's question...please excuse me for this... question is very simple... Why empty class's size is one Byte in C++??? Answer 1:suppose in case of creating array of objects of this empty class, then to distinguish them atleast 1 byte is required ... mE fedup of this answer My Doubt for this answer : If this reason is valid then why hell in C, empty structure's size is zero... Here also anyone can create the array of objects of this empty structure.Here no neeed to distinguise. Is It ???? Answer 2: Since in C++ provides function members so like class test { }; this is also empty class but by default every class has some default member's function... test tObject1=test(); test tObject2(tObject1); or class test { public: void fun(); }; test obj; obj.fun(); so to call this function it may required size atleast 1 byte... BUT I M NOT SUTE FOR WHAT REASON IN C++ THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C....PLEASE U CAN SHARE WHAT'S EXACT REASON????
Truth Can'nt be changed
Here is what the man himself has to say about it - Why is the size of an empty class not zero?[^]
«_Superman_»
I love work. It gives me something to do between weekends. -
Dont bore of this 80's question...please excuse me for this... question is very simple... Why empty class's size is one Byte in C++??? Answer 1:suppose in case of creating array of objects of this empty class, then to distinguish them atleast 1 byte is required ... mE fedup of this answer My Doubt for this answer : If this reason is valid then why hell in C, empty structure's size is zero... Here also anyone can create the array of objects of this empty structure.Here no neeed to distinguise. Is It ???? Answer 2: Since in C++ provides function members so like class test { }; this is also empty class but by default every class has some default member's function... test tObject1=test(); test tObject2(tObject1); or class test { public: void fun(); }; test obj; obj.fun(); so to call this function it may required size atleast 1 byte... BUT I M NOT SUTE FOR WHAT REASON IN C++ THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C....PLEASE U CAN SHARE WHAT'S EXACT REASON????
Truth Can'nt be changed
-
Dont bore of this 80's question...please excuse me for this... question is very simple... Why empty class's size is one Byte in C++??? Answer 1:suppose in case of creating array of objects of this empty class, then to distinguish them atleast 1 byte is required ... mE fedup of this answer My Doubt for this answer : If this reason is valid then why hell in C, empty structure's size is zero... Here also anyone can create the array of objects of this empty structure.Here no neeed to distinguise. Is It ???? Answer 2: Since in C++ provides function members so like class test { }; this is also empty class but by default every class has some default member's function... test tObject1=test(); test tObject2(tObject1); or class test { public: void fun(); }; test obj; obj.fun(); so to call this function it may required size atleast 1 byte... BUT I M NOT SUTE FOR WHAT REASON IN C++ THEY HAVE TAKEN 1 BYTE FOR EMPTY CLASS AND ZERO BYTE FOR C....PLEASE U CAN SHARE WHAT'S EXACT REASON????
Truth Can'nt be changed
-
offcourse C != C++ ...Here offcourse C++ standard requires it so it's there But my question is why they have made like this... Some reason should be for this...
Truth Can'nt be changed
The reason is very subjective. In the below posts you can find the link to Stroustroup site, and his "official" answer. The interesting thing is that the argumentation he provides are good for C as well. IMHO, I think it was just a different "taste" between K&R and B.S. In C a struct is just a "bouch of bytes" and and address is just a "place in memory". In C++ a struct is an "object" and an address is an "object identity" (and two objects must not have the same one). Of course we can discuss if C++ classes and structs are "real" object or just tools to assemble them ... but it is still another matter of "taste".
2 bugs found. > recompile ... 65534 bugs found. :doh: