<?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: Reason #947 why C++ is dangerous &#8211; and certainly not type-safe</title>
	<atom:link href="http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/</link>
	<description>Captain's log</description>
	<lastBuildDate>Thu, 13 Aug 2009 12:35:23 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-22</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 13 Apr 2009 22:57:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-22</guid>
		<description>&lt;p&gt;@ Thomas BOUTON:&lt;/p&gt;

&lt;p&gt;I just read this post too and I was going to say the same thing!  There are flags built in to stop you doing this sort of thing.  I like -Wall -Werror -Wextra -pedantic off the top of my head, there are at least 5 that should be a requirement for any project, I have a standard line of about 10 flags that I apply to all of my projects.&lt;/p&gt;

&lt;p&gt;http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html&lt;/p&gt;

&lt;p&gt;@ everyone:&lt;/p&gt;

&lt;p&gt;I know if you are in bussiness or games programming you might not have a choice but to use Visual Studio, but at least compile under gcc once in a while, even if you don&#039;t release with it, just to make sure that you are creating robust code.  At my work place we have 3 automatic regression/build test machines that every hour checks out a copy of our code and tries to build the Visual Studio project and gcc project for Windows as well as the gcc project for Linux and Mac and then email us if anything fails to build.  The best thing is that each developer doesn&#039;t need to actually have a Windows, Linux and Mac machine to write cross platform code, he quickly gets an idea via email of what will not compile.  It would be great in the future to also have a commit hook so that you can&#039;t even commit if the code is not cross platform.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@ Thomas BOUTON:</p>

<p>I just read this post too and I was going to say the same thing!  There are flags built in to stop you doing this sort of thing.  I like -Wall -Werror -Wextra -pedantic off the top of my head, there are at least 5 that should be a requirement for any project, I have a standard line of about 10 flags that I apply to all of my projects.</p>

<p><a href="http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html</a></p>

<p>@ everyone:</p>

<p>I know if you are in bussiness or games programming you might not have a choice but to use Visual Studio, but at least compile under gcc once in a while, even if you don&#8217;t release with it, just to make sure that you are creating robust code.  At my work place we have 3 automatic regression/build test machines that every hour checks out a copy of our code and tries to build the Visual Studio project and gcc project for Windows as well as the gcc project for Linux and Mac and then email us if anything fails to build.  The best thing is that each developer doesn&#8217;t need to actually have a Windows, Linux and Mac machine to write cross platform code, he quickly gets an idea via email of what will not compile.  It would be great in the future to also have a commit hook so that you can&#8217;t even commit if the code is not cross platform.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas BOUTON</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-21</link>
		<dc:creator>Thomas BOUTON</dc:creator>
		<pubDate>Thu, 02 Apr 2009 13:32:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-21</guid>
		<description>&lt;p&gt;Just found this post today, I&#039;m just one year too late.
Obviously, you are not using correct tools:&lt;/p&gt;

&lt;p&gt;$ cat test.cpp
struct Vec3 {
    float i1,i2,i3;
    Vec3(float toto);
};&lt;/p&gt;

&lt;p&gt;Vec3 v = (2,3,0);
tom@tomdell:~ $ g++ -c -Wall test.cpp
test.cpp:6: warning: left-hand operand of comma has no effect
test.cpp:6: warning: right-hand operand of comma has no effect&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Just found this post today, I&#8217;m just one year too late.
Obviously, you are not using correct tools:</p>

<p>$ cat test.cpp
struct Vec3 {
    float i1,i2,i3;
    Vec3(float toto);
};</p>

<p>Vec3 v = (2,3,0);
tom@tomdell:~ $ g++ -c -Wall test.cpp
test.cpp:6: warning: left-hand operand of comma has no effect
test.cpp:6: warning: right-hand operand of comma has no effect</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Geiller</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-15</link>
		<dc:creator>Patrick Geiller</dc:creator>
		<pubDate>Wed, 02 Jul 2008 17:52:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-15</guid>
		<description>&lt;p&gt;There is some direct initiliazation code in Quake, stuff like Vector = {0, 0, 1}. Vector is defined as float[3], though.&lt;/p&gt;

&lt;p&gt;As for the comma operator, one use in Javascript :&lt;/p&gt;

&lt;p&gt;function doStuffWithNode(node)
{
  if (someInvalidCondition) return Warning(&#039;invalid node&#039;), null
}&lt;/p&gt;

&lt;p&gt;This would call the log code then return null. I really prefer that to opening up braces and using 4 lines to log then return.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>There is some direct initiliazation code in Quake, stuff like Vector = {0, 0, 1}. Vector is defined as float[3], though.</p>

<p>As for the comma operator, one use in Javascript :</p>

<p>function doStuffWithNode(node)
{
  if (someInvalidCondition) return Warning(&#8217;invalid node&#8217;), null
}</p>

<p>This would call the log code then return null. I really prefer that to opening up braces and using 4 lines to log then return.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Groby</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-14</link>
		<dc:creator>Groby</dc:creator>
		<pubDate>Mon, 09 Jun 2008 03:50:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-14</guid>
		<description>&lt;p&gt;Tom: OK, that &lt;em&gt;is&lt;/em&gt; a fairly common case. I&#039;d argue it&#039;s unnecessary, but that&#039;s mostly a stylistic question, so let&#039;s not even go there...&lt;/p&gt;

&lt;p&gt;Michael: I&#039;m a bit disappointed the first flame I got on this blog was &lt;em&gt;that&lt;/em&gt; weak. Ah, where are the good old days of comp.lang.c++ where people knew how to flame ;)&lt;/p&gt;

&lt;p&gt;And the most frustrating bit of C++ are not even the possibility of subtle errors - compile times are horrenduous. (Expect to see a few more articles on that)&lt;/p&gt;

&lt;p&gt;In general: in case anybody thinks this is my &lt;em&gt;only&lt;/em&gt; beef with C++ - it&#039;s reason #947, as I said. It&#039;s just the one thing that caused me to vent.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Tom: OK, that <em>is</em> a fairly common case. I&#8217;d argue it&#8217;s unnecessary, but that&#8217;s mostly a stylistic question, so let&#8217;s not even go there&#8230;</p>

<p>Michael: I&#8217;m a bit disappointed the first flame I got on this blog was <em>that</em> weak. Ah, where are the good old days of comp.lang.c++ where people knew how to flame <img src='http://www.codingadventures.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<p>And the most frustrating bit of C++ are not even the possibility of subtle errors &#8211; compile times are horrenduous. (Expect to see a few more articles on that)</p>

<p>In general: in case anybody thinks this is my <em>only</em> beef with C++ &#8211; it&#8217;s reason #947, as I said. It&#8217;s just the one thing that caused me to vent.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Mrozek</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-13</link>
		<dc:creator>Michael Mrozek</dc:creator>
		<pubDate>Mon, 09 Jun 2008 01:14:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-13</guid>
		<description>&lt;p&gt;From now on I will be insulting people with &quot;You are an ignorant&quot; :D. And while the example does seem silly since the assignment operator is being misused, I agree that C++ is very prone to subtle errors, which can be frustrating at times.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>From now on I will be insulting people with &#8220;You are an ignorant&#8221; <img src='http://www.codingadventures.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . And while the example does seem silly since the assignment operator is being misused, I agree that C++ is very prone to subtle errors, which can be frustrating at times.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Ritchford</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-12</link>
		<dc:creator>Tom Ritchford</dc:creator>
		<pubDate>Mon, 09 Jun 2008 00:34:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-12</guid>
		<description>&lt;p&gt;&quot;Iâ€™ve never seen a case where the comma operator actually was the intent of the programmer and useful in any way except to obfuscate the code.&quot;&lt;/p&gt;

&lt;p&gt;What about this super-common idiom:&lt;/p&gt;

&lt;p&gt;for (int i = 0, size = v-&gt;size(); i &lt; size; ++i)&lt;/p&gt;

&lt;p&gt;?&lt;/p&gt;

&lt;p&gt;(you might not want to use an iterator, perhaps because you want the index as well as the value...)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&#8220;Iâ€™ve never seen a case where the comma operator actually was the intent of the programmer and useful in any way except to obfuscate the code.&#8221;</p>

<p>What about this super-common idiom:</p>

<p>for (int i = 0, size = v-&gt;size(); i &lt; size; ++i)</p>

<p>?</p>

<p>(you might not want to use an iterator, perhaps because you want the index as well as the value&#8230;)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Groby</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-11</link>
		<dc:creator>Groby</dc:creator>
		<pubDate>Sun, 08 Jun 2008 03:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-11</guid>
		<description>&lt;p&gt;Steve: This is a real example, yes. It&#039;s not due to the fact that I waited too long with the ARM (I read it the first time in 92, I think). It&#039;s simply due to the fact that in the environment I work in (Video games) many low level data structures are just that, plain structures. Ergo, no constructor available. It doesn&#039;t help that every game team I&#039;ve ever seen implements their own Vector class, with slightly different semantics ;)&lt;/p&gt;

&lt;p&gt;And my complaint isn&#039;t that C++ doesn&#039;t accomodate this. I&#039;d be perfectly happy with a syntax error. My complaint is that by accidentally typing something that&#039;s &lt;em&gt;clearly&lt;/em&gt; not valid code, all the &quot;magic&quot; imbued in C++ generates working code that&#039;s not even close to what I intended.&lt;/p&gt;

&lt;p&gt;The main complaint: explicit constructors are safer than implicit ones - they should be the default. (Immediately followed by the comma operator)&lt;/p&gt;

&lt;p&gt;Mark: See above - we&#039;ve got plenty of PODs, so the initialization code is unfortunately a valid choice. (There are also plenty of constructors. But as long as I&#039;d get an error if I picked the wrong one, I&#039;d be happy)&lt;/p&gt;

&lt;p&gt;Dumb: Always glad to see a well-reasoned argument.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Steve: This is a real example, yes. It&#8217;s not due to the fact that I waited too long with the ARM (I read it the first time in 92, I think). It&#8217;s simply due to the fact that in the environment I work in (Video games) many low level data structures are just that, plain structures. Ergo, no constructor available. It doesn&#8217;t help that every game team I&#8217;ve ever seen implements their own Vector class, with slightly different semantics <img src='http://www.codingadventures.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<p>And my complaint isn&#8217;t that C++ doesn&#8217;t accomodate this. I&#8217;d be perfectly happy with a syntax error. My complaint is that by accidentally typing something that&#8217;s <em>clearly</em> not valid code, all the &#8220;magic&#8221; imbued in C++ generates working code that&#8217;s not even close to what I intended.</p>

<p>The main complaint: explicit constructors are safer than implicit ones &#8211; they should be the default. (Immediately followed by the comma operator)</p>

<p>Mark: See above &#8211; we&#8217;ve got plenty of PODs, so the initialization code is unfortunately a valid choice. (There are also plenty of constructors. But as long as I&#8217;d get an error if I picked the wrong one, I&#8217;d be happy)</p>

<p>Dumb: Always glad to see a well-reasoned argument.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: stevej</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-10</link>
		<dc:creator>stevej</dc:creator>
		<pubDate>Sun, 08 Jun 2008 01:01:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-10</guid>
		<description>&lt;p&gt;I agree, this is surprising. Is it a boiled down example, or did you actually write this line of code (hoping for a vector so initialized)?&lt;/p&gt;

&lt;p&gt;If the latter case, then perhaps you waited too long to read the ARM. This is in an uncommon usage/style/attempt (in C++), I think.&lt;/p&gt;

&lt;p&gt;No language that I&#039;ve used accomodates every means of expression. Most (even C++) clobber you with a syntax error. Generally.&lt;/p&gt;

&lt;p&gt;Yeah, you got bit here. Try to be nice.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I agree, this is surprising. Is it a boiled down example, or did you actually write this line of code (hoping for a vector so initialized)?</p>

<p>If the latter case, then perhaps you waited too long to read the ARM. This is in an uncommon usage/style/attempt (in C++), I think.</p>

<p>No language that I&#8217;ve used accomodates every means of expression. Most (even C++) clobber you with a syntax error. Generally.</p>

<p>Yeah, you got bit here. Try to be nice.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: dumb</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-9</link>
		<dc:creator>dumb</dc:creator>
		<pubDate>Sat, 07 Jun 2008 13:51:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-9</guid>
		<description>&lt;p&gt;You are an ignorant&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You are an ignorant</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mark K.</title>
		<link>http://www.codingadventures.com/2008/04/reason-947-why-c-is-dangerous-and-certainly-not-type-safe/comment-page-1/#comment-8</link>
		<dc:creator>Mark K.</dc:creator>
		<pubDate>Sat, 07 Jun 2008 13:05:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.codingadventures.com/?p=14#comment-8</guid>
		<description>&lt;p&gt;In general I agree with you that C++ is a horrible language, however, I think in this case you are attacking a straw man. The reason is that you almost never see examples of:&lt;/p&gt;

&lt;p&gt;A a = (x,y,z);  // or
B b = {x,y,z};&lt;/p&gt;

&lt;p&gt;...in real code. The reason is that C++ have been ingrained with the idea that they cannot statically initialize classes using the assignment operator. You will always see that its done with some constructor. Part of the reason for this is that C has just piss-poor support for anything other than scalar values. For example, tuples and dictionaries just don&#039;t exist in C. Even array&#039;s are broken since you can&#039;t in general do:&lt;/p&gt;

&lt;p&gt;C c = {1,2,3};&lt;/p&gt;

&lt;p&gt;for a real type C that you&#039;ve defined. It has to be a struct with no constructors, like you noted in your post.&lt;/p&gt;

&lt;p&gt;Fortunately, some people have heard our complaints and have made C++ marginally more useful. Look at the Boost assignment library for an example of why the comma operator is a good thing to have. Of course, any language that needs a library to help out with something as simple as assignment is probably pretty broken.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>In general I agree with you that C++ is a horrible language, however, I think in this case you are attacking a straw man. The reason is that you almost never see examples of:</p>

<p>A a = (x,y,z);  // or
B b = {x,y,z};</p>

<p>&#8230;in real code. The reason is that C++ have been ingrained with the idea that they cannot statically initialize classes using the assignment operator. You will always see that its done with some constructor. Part of the reason for this is that C has just piss-poor support for anything other than scalar values. For example, tuples and dictionaries just don&#8217;t exist in C. Even array&#8217;s are broken since you can&#8217;t in general do:</p>

<p>C c = {1,2,3};</p>

<p>for a real type C that you&#8217;ve defined. It has to be a struct with no constructors, like you noted in your post.</p>

<p>Fortunately, some people have heard our complaints and have made C++ marginally more useful. Look at the Boost assignment library for an example of why the comma operator is a good thing to have. Of course, any language that needs a library to help out with something as simple as assignment is probably pretty broken.</p>]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.940 seconds -->
