<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Differences between C++ Classes and Structs</title>
	<atom:link href="http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs</link>
	<description>Real-World Computing Experience Distilled</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:04:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bill H.</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-8020</link>
		<dc:creator>Bill H.</dc:creator>
		<pubDate>Mon, 30 Jan 2012 20:04:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-8020</guid>
		<description>By the way, just to clarify my last post and to correct one point above, padding of data members for memory alignment will generally be done in both classes and structs.  The difference is that a struct will have no memory added by the compilers beyond the regular alignment padding, and that alignment padding is also used in C, as well as C++.

Depending on compiler switches and/or certain pragma definitions, padding for alignment can be modified or disabled.</description>
		<content:encoded><![CDATA[<p>By the way, just to clarify my last post and to correct one point above, padding of data members for memory alignment will generally be done in both classes and structs.  The difference is that a struct will have no memory added by the compilers beyond the regular alignment padding, and that alignment padding is also used in C, as well as C++.</p>
<p>Depending on compiler switches and/or certain pragma definitions, padding for alignment can be modified or disabled.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill H.</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-8019</link>
		<dc:creator>Bill H.</dc:creator>
		<pubDate>Mon, 30 Jan 2012 20:00:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-8019</guid>
		<description>There is a significant difference between a class and a structure that has not been mentioned beyond the default access level.

The C++ language specification allows compiler writers to add abitrary internal data to a class instance, and this data can be either before or after the regular class data in memory.  Some compilers do this.  Almost all compilers do this if Run Time Type Information (RTTI) is enabled at compiler time.

More importantly, any future compiler can increase the size of class instances in any future compiler without violating the language specification.

The C++ language specification prohibits adding any data to a structure that contains only non-virtual members.  A pointer to a vtable will be added if the struct contains virtual members.

A structure with &#039;no&#039; virtual members is guaranteed to be the size of it&#039;s data elements plus an padding bytes necessary to aligh data members for the current memory alignment.  

Thus, unlike a class, the address of a structure with no virtual members is guaranteed to be the same as the address of the first data element in the structure.  As mentioned earlier by MG, the struct exists in C++ to allow compatibility with C code. 

However, a struct can be occasionally preferable in C++ code.  AI a C++ container class with thousands of instances, as adding padding data &#039;can&#039; greatly increase memory utilization.  This is because some memory allocators, in order to reduce memory fragmentation, only allocate sizes that are powers of two up to some maximum power of two.  Thus, adding a single byte to a size that is already a small power of two can double memory utilization.</description>
		<content:encoded><![CDATA[<p>There is a significant difference between a class and a structure that has not been mentioned beyond the default access level.</p>
<p>The C++ language specification allows compiler writers to add abitrary internal data to a class instance, and this data can be either before or after the regular class data in memory.  Some compilers do this.  Almost all compilers do this if Run Time Type Information (RTTI) is enabled at compiler time.</p>
<p>More importantly, any future compiler can increase the size of class instances in any future compiler without violating the language specification.</p>
<p>The C++ language specification prohibits adding any data to a structure that contains only non-virtual members.  A pointer to a vtable will be added if the struct contains virtual members.</p>
<p>A structure with &#8216;no&#8217; virtual members is guaranteed to be the size of it&#8217;s data elements plus an padding bytes necessary to aligh data members for the current memory alignment.  </p>
<p>Thus, unlike a class, the address of a structure with no virtual members is guaranteed to be the same as the address of the first data element in the structure.  As mentioned earlier by MG, the struct exists in C++ to allow compatibility with C code. </p>
<p>However, a struct can be occasionally preferable in C++ code.  AI a C++ container class with thousands of instances, as adding padding data &#8216;can&#8217; greatly increase memory utilization.  This is because some memory allocators, in order to reduce memory fragmentation, only allocate sizes that are powers of two up to some maximum power of two.  Thus, adding a single byte to a size that is already a small power of two can double memory utilization.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NeoCambell</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-8018</link>
		<dc:creator>NeoCambell</dc:creator>
		<pubDate>Sun, 22 Jan 2012 02:53:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-8018</guid>
		<description>Another nice explanation to the same problem can be found at http://www.expertcore.org/viewtopic.php?f=8&amp;p=9281</description>
		<content:encoded><![CDATA[<p>Another nice explanation to the same problem can be found at <a href="http://www.expertcore.org/viewtopic.php?f=8&#038;p=9281" rel="nofollow">http://www.expertcore.org/viewtopic.php?f=8&#038;p=9281</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhiraj</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-8002</link>
		<dc:creator>Dhiraj</dc:creator>
		<pubDate>Thu, 08 Dec 2011 17:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-8002</guid>
		<description>i am asking you the correct answer. and instead of it you are providing me silly comments. hoples</description>
		<content:encoded><![CDATA[<p>i am asking you the correct answer. and instead of it you are providing me silly comments. hoples</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shri "the final comment" amin</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-7953</link>
		<dc:creator>shri "the final comment" amin</dc:creator>
		<pubDate>Sun, 11 Sep 2011 02:59:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-7953</guid>
		<description>this is the last comment regarding this matter. people suck, especially computer geeks and programming gods.</description>
		<content:encoded><![CDATA[<p>this is the last comment regarding this matter. people suck, especially computer geeks and programming gods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jadhav Harshawardhan</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-7952</link>
		<dc:creator>Jadhav Harshawardhan</dc:creator>
		<pubDate>Fri, 09 Sep 2011 12:35:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-7952</guid>
		<description>Their are only three diffrance between  struture and class is ,
1) default accsss specifierin class i.e private for class and public for struture 
2) keyword class for class and struct for struture 
3) Inheritance between classes is also private by default, and inheritance      between structs is public by default</description>
		<content:encoded><![CDATA[<p>Their are only three diffrance between  struture and class is ,<br />
1) default accsss specifierin class i.e private for class and public for struture<br />
2) keyword class for class and struct for struture<br />
3) Inheritance between classes is also private by default, and inheritance      between structs is public by default</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: harshita</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-7937</link>
		<dc:creator>harshita</dc:creator>
		<pubDate>Mon, 08 Aug 2011 11:12:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-7937</guid>
		<description>other than all d bullshits posted, this somehow convinced me n helped m ein finding d ans. as dis is a very common ques wrt d interviews, n lets c if dat helps me or not.</description>
		<content:encoded><![CDATA[<p>other than all d bullshits posted, this somehow convinced me n helped m ein finding d ans. as dis is a very common ques wrt d interviews, n lets c if dat helps me or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Léo</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-7935</link>
		<dc:creator>Léo</dc:creator>
		<pubDate>Wed, 20 Jul 2011 18:23:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-7935</guid>
		<description>@Sunil: Are you sure about padding?</description>
		<content:encoded><![CDATA[<p>@Sunil: Are you sure about padding?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nandhini</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-7933</link>
		<dc:creator>Nandhini</dc:creator>
		<pubDate>Wed, 13 Jul 2011 15:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-7933</guid>
		<description>Can anyone pls temme if a main function is user defined or built-in type?? It was asked by my HOD mam. And am supposed to give her the correct answer. so pls anyone help me.....do post ur replies as soon as possible...</description>
		<content:encoded><![CDATA[<p>Can anyone pls temme if a main function is user defined or built-in type?? It was asked by my HOD mam. And am supposed to give her the correct answer. so pls anyone help me&#8230;..do post ur replies as soon as possible&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keshav</title>
		<link>http://blog.stevedoria.net/20050913/differences-between-cpp-classes-and-structs/comment-page-2#comment-7931</link>
		<dc:creator>Keshav</dc:creator>
		<pubDate>Fri, 08 Jul 2011 08:04:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevedoria.net/?p=21#comment-7931</guid>
		<description>Hi sunil, can you explain the concept of padding.</description>
		<content:encoded><![CDATA[<p>Hi sunil, can you explain the concept of padding.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

