<?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: &quot;const&quot; Keyword Explained</title>
	<atom:link href="http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html</link>
	<description>Making Your Code Faster, Stronger, Safer…</description>
	<lastBuildDate>Tue, 31 Aug 2010 16:47:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Umesh Patel</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-3489</link>
		<dc:creator>Umesh Patel</dc:creator>
		<pubDate>Wed, 17 Feb 2010 11:28:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-3489</guid>
		<description>Does any one know How const objects are imlemented in compiler?</description>
		<content:encoded><![CDATA[<p>Does any one know How const objects are imlemented in compiler?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sreekanth</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-264</link>
		<dc:creator>sreekanth</dc:creator>
		<pubDate>Thu, 05 Mar 2009 09:51:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-264</guid>
		<description>nice indepth knownledge</description>
		<content:encoded><![CDATA[<p>nice indepth knownledge</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Volatile: C Keyword Myths Dispelled &#124; Safer Code - Secure Coding In C C++ And More..</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-195</link>
		<dc:creator>Volatile: C Keyword Myths Dispelled &#124; Safer Code - Secure Coding In C C++ And More..</dc:creator>
		<pubDate>Tue, 24 Feb 2009 14:06:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-195</guid>
		<description>[...] time we explained the real meaning of const keyword, this time it&#8217;s going to be Volatile, the other sibling of this most misunderstood duo in C [...]</description>
		<content:encoded><![CDATA[<p>[...] time we explained the real meaning of const keyword, this time it&rsquo;s going to be Volatile, the other sibling of this most misunderstood duo in C [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shantanu Goel</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-138</link>
		<dc:creator>Shantanu Goel</dc:creator>
		<pubDate>Tue, 10 Feb 2009 14:12:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-138</guid>
		<description>@Ric: oops, what a blunder :) ..fixed..thanks..</description>
		<content:encoded><![CDATA[<p>@Ric: oops, what a blunder <img src='http://www.safercode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ..fixed..thanks..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ric</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-137</link>
		<dc:creator>Ric</dc:creator>
		<pubDate>Tue, 10 Feb 2009 13:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-137</guid>
		<description>int main() is missing a return statement, or maybe I&#039;m just old fashioned</description>
		<content:encoded><![CDATA[<p>int main() is missing a return statement, or maybe I&#8217;m just old fashioned</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-135</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 10 Feb 2009 10:11:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-135</guid>
		<description>the const keyword does not, even i the c++ standard, mean that  this is not modifiably though that name const is mutable. 

Please red the C++ faq lite. It has a long, and correct, description of const.

http://www.parashift.com/c++-faq-lite/const-correctness.html</description>
		<content:encoded><![CDATA[<p>the const keyword does not, even i the c++ standard, mean that  this is not modifiably though that name const is mutable. </p>
<p>Please red the C++ faq lite. It has a long, and correct, description of const.</p>
<p><a href="http://www.parashift.com/c++-faq-lite/const-correctness.html" rel="nofollow">http://www.parashift.com/c++-faq-lite/const-correctness.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: norbert</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-132</link>
		<dc:creator>norbert</dc:creator>
		<pubDate>Mon, 09 Feb 2009 19:19:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-132</guid>
		<description>sorry for the post above, I flumbled and sent it too early

foo_resize_tag_array could do all kind of thing to foo, including modfying the content pointed by tag, which was return by foo_look_for_tag() and could very well be a reference to some part of a buffer under foo.

this would not raise a compiler error nor warning, and the writter of foo_intern_tag() could have very honnestly claimed that tag is const, as far as his use of it goes.

const &#039;may&#039; use the compiler, and the compiler is much better than human to detect these gatchas. A programming trusting const is looking for trouble.

Furthermore, many time prototypes are not const correct due to legacy isssues (the code had at one point to be compiled with K&amp;R compiler which did not support const, and nobody revisited the code to add the conditional to allow double-compile... especially since it IS a perforamce issue, and most of the code is not performance critical.

I personally tend to use const for low-level functions that I can guarantee will not have any side-effet (as illustrated above). And it is true that most of the time it has no performance impact, because most of the time the compiler can determine the cosnt status by itself (or canot rely on it). Still on the few case where it can, it is a free lunch. And I&#039;m banking on the evolution of the compiler and the standard that will make const be more and more useful (think anti-aliasing and other effort to allow the optimizer to do its job)</description>
		<content:encoded><![CDATA[<p>sorry for the post above, I flumbled and sent it too early</p>
<p>foo_resize_tag_array could do all kind of thing to foo, including modfying the content pointed by tag, which was return by foo_look_for_tag() and could very well be a reference to some part of a buffer under foo.</p>
<p>this would not raise a compiler error nor warning, and the writter of foo_intern_tag() could have very honnestly claimed that tag is const, as far as his use of it goes.</p>
<p>const &#8216;may&#8217; use the compiler, and the compiler is much better than human to detect these gatchas. A programming trusting const is looking for trouble.</p>
<p>Furthermore, many time prototypes are not const correct due to legacy isssues (the code had at one point to be compiled with K&amp;R compiler which did not support const, and nobody revisited the code to add the conditional to allow double-compile&#8230; especially since it IS a perforamce issue, and most of the code is not performance critical.</p>
<p>I personally tend to use const for low-level functions that I can guarantee will not have any side-effet (as illustrated above). And it is true that most of the time it has no performance impact, because most of the time the compiler can determine the cosnt status by itself (or canot rely on it). Still on the few case where it can, it is a free lunch. And I&#8217;m banking on the evolution of the compiler and the standard that will make const be more and more useful (think anti-aliasing and other effort to allow the optimizer to do its job)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: norbert</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-131</link>
		<dc:creator>norbert</dc:creator>
		<pubDate>Mon, 09 Feb 2009 19:06:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-131</guid>
		<description>[Well, not unknowingly - that *should* cause a compiler error. (I’m pretty sure that’s in the spec) Of course, he may explicitly cast away const, but then we revert to my statement above.]

Not necesseraly: look at:

int a(....)
{
struct foo* foo
char* tag;

    tag  = foo_look_for_tag(foo)

   rc = foo_intern_tag(foo, tag);
...
}

foo_intern_tag(struct foo* foo, cosnt char* tag)
{

     foo_resize_tag_array(foo, 1);

}</description>
		<content:encoded><![CDATA[<p>[Well, not unknowingly - that *should* cause a compiler error. (I’m pretty sure that’s in the spec) Of course, he may explicitly cast away const, but then we revert to my statement above.]</p>
<p>Not necesseraly: look at:</p>
<p>int a(&#8230;.)<br />
{<br />
struct foo* foo<br />
char* tag;</p>
<p>    tag  = foo_look_for_tag(foo)</p>
<p>   rc = foo_intern_tag(foo, tag);<br />
&#8230;<br />
}</p>
<p>foo_intern_tag(struct foo* foo, cosnt char* tag)<br />
{</p>
<p>     foo_resize_tag_array(foo, 1);</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smitty</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-126</link>
		<dc:creator>Smitty</dc:creator>
		<pubDate>Mon, 09 Feb 2009 11:48:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-126</guid>
		<description>[The user cannot assume that the buffer he passed to func won’t be changed]  
Well, that&#039;s the &#039;promise&#039; the author of the function is making by using the const modifier.  Of course, he may renege on that promise, as I&#039;ve stated before, but if he does he&#039;s foolish.  He should either not declare the parameter as const, or not throw the const away.

[It can easily be if the func implementer decides to (knowingly or unknowingly) take another pointer, point it to buf and then alter away the contents to his self-contentness..]
Well, not unknowingly - that *should* cause a compiler error. (I&#039;m pretty sure that&#039;s in the spec) Of course, he may explicitly cast away const, but then we revert to my statement above.

[Whether a compiler will optimize or not with const, depends totally on the compiler because the spec doesn’t say anything about it.]
Yes, that&#039;s my understanding as well, I would never advocate using const for performance, in fact, that&#039;s been my stance from my very first post.  Norbert disagrees, and thinks const is all about compiler optimization.</description>
		<content:encoded><![CDATA[<p>[The user cannot assume that the buffer he passed to func won’t be changed]<br />
Well, that&#8217;s the &#8216;promise&#8217; the author of the function is making by using the const modifier.  Of course, he may renege on that promise, as I&#8217;ve stated before, but if he does he&#8217;s foolish.  He should either not declare the parameter as const, or not throw the const away.</p>
<p>[It can easily be if the func implementer decides to (knowingly or unknowingly) take another pointer, point it to buf and then alter away the contents to his self-contentness..]<br />
Well, not unknowingly &#8211; that *should* cause a compiler error. (I&#8217;m pretty sure that&#8217;s in the spec) Of course, he may explicitly cast away const, but then we revert to my statement above.</p>
<p>[Whether a compiler will optimize or not with const, depends totally on the compiler because the spec doesn’t say anything about it.]<br />
Yes, that&#8217;s my understanding as well, I would never advocate using const for performance, in fact, that&#8217;s been my stance from my very first post.  Norbert disagrees, and thinks const is all about compiler optimization.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shantanu Goel</title>
		<link>http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-122</link>
		<dc:creator>Shantanu Goel</dc:creator>
		<pubDate>Sun, 08 Feb 2009 14:06:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2009/02/04/const-keyword-explained.html#comment-122</guid>
		<description>@Smitty: The user cannot assume that the buffer he passed to func won&#039;t be changed. It can easily be if the func implementer decides to (knowingly or unknowingly) take another pointer, point it to buf and then alter away the contents to his self-contentness..
Whether a compiler will optimize or not with const, depends totally on the compiler because the spec doesn&#039;t say anything about it. For example, if you were to pick up one of the guides for TI CCS (Optimizing Compiler Users&#039; Guide - SPRU198) you can see in how many ways they use const to generate optimized code.</description>
		<content:encoded><![CDATA[<p>@Smitty: The user cannot assume that the buffer he passed to func won&#8217;t be changed. It can easily be if the func implementer decides to (knowingly or unknowingly) take another pointer, point it to buf and then alter away the contents to his self-contentness..<br />
Whether a compiler will optimize or not with const, depends totally on the compiler because the spec doesn&#8217;t say anything about it. For example, if you were to pick up one of the guides for TI CCS (Optimizing Compiler Users&#8217; Guide &#8211; SPRU198) you can see in how many ways they use const to generate optimized code.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
