<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Strainu onLine &#187; C</title>
	<atom:link href="http://www.strainu.ro/category/programming/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.strainu.ro</link>
	<description>Blogul unui automatist</description>
	<lastBuildDate>Fri, 28 Oct 2011 15:46:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Network Programming Homeworks</title>
		<link>http://www.strainu.ro/software/34/</link>
		<comments>http://www.strainu.ro/software/34/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 14:16:46 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://www.strainu.ro/site/?p=450</guid>
		<description><![CDATA[Network Programming Homeworks from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Valentin Cristea. The archive contains a homework made in Java. Themes: RPC (Remote Procedure Call), Sorting trees using MPI, Secure chat server in JAVA, Bidding system using CORBA. The software is distributed under CC-GNU GPL license. Download Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p><strong>Network Programming Homeworks</strong> from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Valentin Cristea. The archive contains a homework made in Java. Themes: RPC (Remote Procedure Call), Sorting trees using MPI, Secure chat server in JAVA, Bidding system using CORBA.<br />
<span id="more-450"></span></p>
<p>The software is distributed under <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL license</a>.</p>
<p><a href="http://www.strainu.ro/tracker/downi.php?id=teme_sprc" target="_blank"><strong>Download</strong></a></p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F34%2F&amp;t=Network%20Programming%20Homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Network%20Programming%20Homeworks%20-%20http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F34%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F34%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Network%20Programming%20Homeworks&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F34%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F34%2F&amp;title=Network%20Programming%20Homeworks&amp;bodytext=Network%20Programming%20Homeworks%20from%20the%20Automatics%20and%20Computer%20Science%20Faculty%2C%20UPB%2C%205th%20year%2C%20prof.%20Valentin%20Cristea.%20The%20archive%20contains%20a%20homework%20made%20in%20Java.%20Themes%3A%20RPC%20%28Remote%20Procedure%20Call%29%2C%20Sorting%20trees%20using%20MPI%2C%20Secure%20chat%20server%20in%20J" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F34%2F&amp;title=Network%20Programming%20Homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/software/34/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parallel Algorithms Homeworks</title>
		<link>http://www.strainu.ro/software/33/</link>
		<comments>http://www.strainu.ro/software/33/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 14:06:02 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://www.strainu.ro/site/?p=448</guid>
		<description><![CDATA[Parallel Algorithms Homeworks from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Valentin Cristea. The archive contains a homework made in Java. Themes: Parallel Game of Life with OpenMP, Sudoku with Replicated Workers, image manipulation (filters, Huffman coding), routing tables. The software is distributed under CC-GNU GPL license. Download Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p><strong>Parallel Algorithms Homeworks</strong> from the Automatics and Computer Science Faculty, UPB, 5th year, prof. Valentin Cristea. The archive contains a homework made in Java. Themes: Parallel Game of Life with OpenMP, Sudoku with Replicated Workers, image manipulation (filters, Huffman coding), routing tables.<br />
<span id="more-448"></span></p>
<p>The software is distributed under <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL license</a>.</p>
<p><a href="http://www.strainu.ro/tracker/downi.php?id=teme_app" target="_blank"><strong>Download</strong></a> </p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F33%2F&amp;t=Parallel%20Algorithms%20Homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Parallel%20Algorithms%20Homeworks%20-%20http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F33%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F33%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Parallel%20Algorithms%20Homeworks&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F33%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F33%2F&amp;title=Parallel%20Algorithms%20Homeworks&amp;bodytext=Parallel%20Algorithms%20Homeworks%20from%20the%20Automatics%20and%20Computer%20Science%20Faculty%2C%20UPB%2C%205th%20year%2C%20prof.%20Valentin%20Cristea.%20The%20archive%20contains%20a%20homework%20made%20in%20Java.%20Themes%3A%20Parallel%20Game%20of%20Life%20with%20OpenMP%2C%20Sudoku%20with%20Replicated%20Workers%2C%20image%20mani" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F33%2F&amp;title=Parallel%20Algorithms%20Homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/software/33/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operating Systems design homeworks</title>
		<link>http://www.strainu.ro/software/29/</link>
		<comments>http://www.strainu.ro/software/29/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 13:20:46 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.strainu.ro/site/?p=438</guid>
		<description><![CDATA[Operating Systems design homeworks from the Automatics and Computer Science Faculty, UPB, 4th year, prof. Octavian Purdilă. Themes: system calls, UART driver, file system driver, firewall, RAID software. The software is distributed under CC-GNU GPL license. Download Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p><strong>Operating Systems design homeworks</strong> from the Automatics and Computer Science Faculty, UPB, 4th year, prof. Octavian Purdilă. Themes: system calls, UART driver, file system driver, firewall, RAID software.<br />
<span id="more-438"></span></p>
<p>The software is distributed under <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL license</a>.</p>
<p><a href="http://www.strainu.ro/tracker/downi.php?id=teme_pso" target="_blank"><strong>Download</strong></a> </p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F&amp;t=Operating%20Systems%20design%20homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Operating%20Systems%20design%20homeworks%20-%20http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Operating%20Systems%20design%20homeworks&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F&amp;title=Operating%20Systems%20design%20homeworks&amp;bodytext=Operating%20Systems%20design%20homeworks%20from%20the%20Automatics%20and%20Computer%20Science%20Faculty%2C%20UPB%2C%204th%20year%2C%20prof.%20Octavian%20Purdil%C4%83.%20Themes%3A%20system%20calls%2C%20UART%20driver%2C%20file%20system%20driver%2C%20firewall%2C%20RAID%20software.%0D%0A%0D%0A%0D%0AThe%20software%20is%20distributed%20under%20CC-GNU" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F&amp;title=Operating%20Systems%20design%20homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/software/29/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parallel Computing homeworks</title>
		<link>http://www.strainu.ro/software/28/</link>
		<comments>http://www.strainu.ro/software/28/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 13:08:32 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Poli]]></category>

		<guid isPermaLink="false">http://www.strainu.ro/site/?p=436</guid>
		<description><![CDATA[Parallel Computing homeworks from the Automatics and Computer Science Faculty, 4th year, prof. Nicolae Tapuş. Subjects: MPI, OpenMPI, pthreads, parallel Sudoku solver and generator. The software is distributed under CC-GNU GPL license. Download Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p><strong>Parallel Computing homeworks</strong> from the Automatics and Computer Science Faculty, 4th year, prof. Nicolae Tapuş. Subjects:</p>
<ul>
<li>MPI,</li>
<li>OpenMPI,</li>
<li>pthreads,</li>
<li>parallel Sudoku solver and generator.</li>
</ul>
<p><span id="more-436"></span></p>
<p>The software is distributed under <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL license</a>.</p>
<p><a href="http://www.strainu.ro/tracker/downi.php?id=teme_apc" target="_blank"><strong>Download</strong></a></p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F28%2F&amp;t=Parallel%20Computing%20homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Parallel%20Computing%20homeworks%20-%20http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F28%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F28%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Parallel%20Computing%20homeworks&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F28%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F28%2F&amp;title=Parallel%20Computing%20homeworks&amp;bodytext=Parallel%20Computing%20homeworks%20from%20the%20Automatics%20and%20Computer%20Science%20Faculty%2C%204th%20year%2C%20prof.%20Nicolae%20Tapu%C5%9F.%20Subjects%3A%0D%0A%0D%0A%09MPI%2C%0D%0A%09OpenMPI%2C%0D%0A%09pthreads%2C%0D%0A%09parallel%20Sudoku%20solver%20and%20generator.%0D%0A%0D%0A%0D%0A%0D%0AThe%20software%20is%20distributed%20under%20CC-GNU%20GPL%20licen" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F28%2F&amp;title=Parallel%20Computing%20homeworks" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/software/28/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The const keyword (part 2)</title>
		<link>http://www.strainu.ro/programming/c/the-const-keyword-part-2/</link>
		<comments>http://www.strainu.ro/programming/c/the-const-keyword-part-2/#comments</comments>
		<pubDate>Tue, 29 May 2007 18:54:04 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[const]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/the-const-keyword-part-2/</guid>
		<description><![CDATA[In part 1 we introduced the const keyword. Today we&#8217;ll talk about constant pointers. Let&#8217;s say you want to define a constant pointer. Which of the following declarations will you use? const int* v1; int* const v2; const int * const v3; The answer is: the second or the third. The first declaration defines a [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>In <a href="http://codertricks.strainu.ro/c/2007/05/24/the-const-keyword-part-1/" target="_blank">part 1</a> we introduced the <em>const</em> keyword. Today we&#8217;ll talk about constant pointers.</p></blockquote>
<p>Let&#8217;s say you want to define a constant pointer. Which of the following declarations will you use?</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">const</span> <span style="color: #993333;">int</span><span style="color: #339933;">*</span> v1<span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span><span style="color: #339933;">*</span> <span style="color: #993333;">const</span> v2<span style="color: #339933;">;</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span> <span style="color: #993333;">const</span> v3<span style="color: #339933;">;</span></div></div>
<p>The answer is: the second or the third. The first declaration defines a pointer to a constant integer and the third one defines a constant pointer to a constant integer.</p>
<p>Another interesting case is when defining a constant char array (credits go to <a href="http://udrepper.livejournal.com/15119.html" target="_blank">Ulrich Drepper</a>, link via <a href="http://cs.pub.ro/~ixlabs/?cat=8" target="_blank">RazvanD</a>):</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;hello&quot;</span><span style="color: #339933;">;</span><br />
strcpy <span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;bye&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
puts <span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Although this code will give a warning (<em>passing `const char *&#8217; as argument 1 of `strcpy(char *, const char *)&#8217; discards qualifiers</em> is the exact message on Dev-C++), it will run, because s is allocated in the heap, so it is treated much like a pointer. You can force the value to be constant by adding the <em>static</em> keyword, wich will force the compiler to allocate <strong>s</strong> in read-only memory:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">static</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;hello&quot;</span><span style="color: #339933;">;</span></div></div>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-2%2F&amp;t=The%20const%20keyword%20%28part%202%29" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=The%20const%20keyword%20%28part%202%29%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-2%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-2%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=The%20const%20keyword%20%28part%202%29&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-2%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-2%2F&amp;title=The%20const%20keyword%20%28part%202%29&amp;bodytext=In%20part%201%20we%20introduced%20the%20const%20keyword.%20Today%20we%27ll%20talk%20about%20constant%20pointers.%0D%0ALet%27s%20say%20you%20want%20to%20define%20a%20constant%20pointer.%20Which%20of%20the%20following%20declarations%20will%20you%20use%3F%0D%0A%0D%0A%0D%0Aconst%20int%2A%20v1%3B%0D%0Aint%2A%20const%20v2%3B%0D%0Aconst%20int%20%2A%20const%20v3%3B%0D%0A%0D%0A%0D%0AT" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-2%2F&amp;title=The%20const%20keyword%20%28part%202%29" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/the-const-keyword-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The const keyword (part 1)</title>
		<link>http://www.strainu.ro/programming/c/the-const-keyword-part-1/</link>
		<comments>http://www.strainu.ro/programming/c/the-const-keyword-part-1/#comments</comments>
		<pubDate>Wed, 23 May 2007 21:48:55 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[const]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/the-const-keyword-part-1/</guid>
		<description><![CDATA[This article will not actually present any tricks, it will be an introduction in the const keyword. In part 2, we will present the const and volatile pointers, which behave a little weird. First of all, let&#8217;s see what the const modifier means in the C standard. Basically, a const variable is one who&#8217;s value [...]]]></description>
			<content:encoded><![CDATA[<p>This article will not actually present any tricks, it will be an introduction in the <em>const</em> keyword. In part 2, we will present the <strong>const and volatile pointers</strong>, which behave a little weird.</p>
<p>First of all, let&#8217;s see what the <strong>const</strong> modifier means  in the <a href="http://www.iso-9899.info/wiki/Main_Page" target="_blank">C standard</a>. Basically, a const variable is one who&#8217;s value can&#8217;t be changed. Actually,  things are not so simple &#8211; as we&#8217;ll see later, you can change a constant variable. The standard states that &#8220;If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined.&#8221;  On some architectures, constant variables are put in a special section (sometimes called <em>.rodata</em> &#8211; from Read Only DATA) of the program by the compiler.</p>
<p>If you want to define a constant in C/C++, you can write:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">const</span> <span style="color: #993333;">int</span> v1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//the usual way</span><br />
<span style="color: #993333;">int</span> <span style="color: #993333;">const</span> v2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//also legal</span></div></div>
<p>Both declarations mean the same thing: define a new integer with a fixed value. So, if you want to change the value of v1, how would you do it? By using pointers:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">const</span> <span style="color: #993333;">int</span> v1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//define a constant</span><br />
<span style="color: #993333;">int</span><span style="color: #339933;">*</span> v2 <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>v1<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//define a pointer to v1</span><br />
<span style="color: #339933;">*</span>v2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//change the value</span></div></div>
<p>Of course, you shouldn&#8217;t do that, as the are no guarantees that the result will be what you expect it to be, but with most compilers, v1 will be 5 after running the code presented above.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-1%2F&amp;t=The%20const%20keyword%20%28part%201%29" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=The%20const%20keyword%20%28part%201%29%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-1%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-1%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=The%20const%20keyword%20%28part%201%29&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-1%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-1%2F&amp;title=The%20const%20keyword%20%28part%201%29&amp;bodytext=This%20article%20will%20not%20actually%20present%20any%20tricks%2C%20it%20will%20be%20an%20introduction%20in%20the%20const%20keyword.%20In%20part%202%2C%20we%20will%20present%20the%20const%20and%20volatile%20pointers%2C%20which%20behave%20a%20little%20weird.%0D%0A%0D%0AFirst%20of%20all%2C%20let%27s%20see%20what%20the%20const%20modifier%20means%20%20in%20" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fthe-const-keyword-part-1%2F&amp;title=The%20const%20keyword%20%28part%201%29" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/the-const-keyword-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple debugging in kernel programming</title>
		<link>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/</link>
		<comments>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/#comments</comments>
		<pubDate>Thu, 17 May 2007 07:17:07 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[kernel]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/simple-debugging-in-kernel-programming/</guid>
		<description><![CDATA[When programming Linux kernel modules, you have limited debugging options. The main way is to use the printk function (the kernel equivalent of printf). If you want to give as much information as possible, you could use some of the macros that the language offers you, such as __FILE__ or __line__. Here is a small [...]]]></description>
			<content:encoded><![CDATA[<p>When programming Linux kernel modules, you have limited debugging options. The main way is to use the <strong>printk</strong> function (the kernel equivalent of printf). If you want to give as much information as possible, you could use some of the macros that the language offers you, such as <em>__FILE__</em> or <em>__line__</em>. Here is a small snippet you could use in your modules:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define DEBUG 1</span><br />
<span style="color: #339933;">#if DEBUG</span><br />
<span style="color: #339933;">#define Dprintk(format, ...) \<br />
printk (KERN_ALERT &quot;[%s]:FUNC:%s:line:%d: &quot; format, __FILE__, \<br />
__func__, __LINE__, __VA_ARGS__)</span><br />
<span style="color: #339933;">#else</span><br />
<span style="color: #339933;">#define Dprintk(format, ...) do {}while(0)</span><br />
<span style="color: #339933;">#endif</span></div></div>
<p>You can use the same code in userspace programs by replacing <strong>printk</strong> with <strong>printf</strong>. And just in case you&#8217;re wondering what&#8217;s with the empty <strong>do-while</strong>, you might want to take a look at <a href="http://codertricks.strainu.ro/c/2007/05/04/macros-using-dowhile0/" target="_blank">this older article</a>.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;t=Simple%20debugging%20in%20kernel%20programming" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Simple%20debugging%20in%20kernel%20programming%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Simple%20debugging%20in%20kernel%20programming&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;title=Simple%20debugging%20in%20kernel%20programming&amp;bodytext=When%20programming%20Linux%20kernel%20modules%2C%20you%20have%20limited%20debugging%20options.%20The%20main%20way%20is%20to%20use%20the%20printk%20function%20%28the%20kernel%20equivalent%20of%20printf%29.%20If%20you%20want%20to%20give%20as%20much%20information%20as%20possible%2C%20you%20could%20use%20some%20of%20the%20macros%20that%20the%20la" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;title=Simple%20debugging%20in%20kernel%20programming" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A little fun with cdecl</title>
		<link>http://www.strainu.ro/programming/c/a-little-fun-with-cdecl/</link>
		<comments>http://www.strainu.ro/programming/c/a-little-fun-with-cdecl/#comments</comments>
		<pubDate>Mon, 14 May 2007 21:05:16 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[cdecl]]></category>
		<category><![CDATA[Jokes&Fun]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/a-little-fun-with-cdecl/</guid>
		<description><![CDATA[One of my teachers decided one day that he should write a pointer to an array of functions receiving a pointer to a function receiving an int and returning a pointer to a function receiving an array of pointers to int and returning int and an int and returning a pointer to a function receiving [...]]]></description>
			<content:encoded><![CDATA[<p>One of my teachers decided one day that he should write a <em>pointer to an array of functions receiving a pointer to a function receiving an int and returning a pointer to a function receiving an array of pointers to int and returning int and an int and returning a pointer to a function receiving a pointer to a function receiving a pointer to an array of int and an int and returning a pointer to int and returning a function receiving int and returning int.</em></p>
<p>Fun, huh? <img src='http://www.strainu.ro/site/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Let&#8217;s try one more time:</p>
<pre>
a pointer to an array of functions
|  receiving a pointer to a function
|               |  receiving an int
|               |  returning a pointer to a function
|               |               |  receiving an array of pointer to int
|               |               |  returning int
|            an int
|  returning a pointer to a function
|               |  receiving a pointer to a function
|               |               |  receiving a pointer to an array of int
|               |               |            an int
|               |               |  returning a pointer to int
|               |  returning a function
|               |               |  receiving int
|               |               |  returning int</pre>
<p>It does sounded quite tricky to me. Still, he managed to write it down in just 10 minutes. The secret? <a href="http://www.boutell.com/lsm/lsmbyid.cgi/002103" target="_blank">Cdecl</a>. Cdecl reads files for statements which should be translated to C or C++. Six different statement are supported: <strong>declare</strong> composes a C type-declaration, <strong>cast</strong> composes a C type-cast, and so on. The grammar is described in full in <a href="http://www.die.net/doc/linux/man/man1/cdecl.1.html" target="_blank">the man page</a>.</p>
<p>And here is the result for the function described above:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">int ((*(*f)[] (int (*( * )(int))(int *[]), int))(int * ( * ) (int ( * )[], int)))(int)</div></div>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fa-little-fun-with-cdecl%2F&amp;t=A%20little%20fun%20with%20cdecl" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=A%20little%20fun%20with%20cdecl%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fa-little-fun-with-cdecl%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fa-little-fun-with-cdecl%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=A%20little%20fun%20with%20cdecl&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fa-little-fun-with-cdecl%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fa-little-fun-with-cdecl%2F&amp;title=A%20little%20fun%20with%20cdecl&amp;bodytext=One%20of%20my%20teachers%20decided%20one%20day%20that%20he%20should%20write%20a%20pointer%20to%20an%20array%20of%20functions%20receiving%20a%20pointer%20to%20a%20function%20receiving%20an%20int%20and%20returning%20a%20pointer%20to%20a%20function%20receiving%20an%20array%20of%20pointers%20to%20int%20and%20returning%20int%20and%20an%20int%20and" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fa-little-fun-with-cdecl%2F&amp;title=A%20little%20fun%20with%20cdecl" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/a-little-fun-with-cdecl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to read the bits in a IEEE 754 number?</title>
		<link>http://www.strainu.ro/programming/c/how-to-read-the-bits-in-a-ieee-754-number/</link>
		<comments>http://www.strainu.ro/programming/c/how-to-read-the-bits-in-a-ieee-754-number/#comments</comments>
		<pubDate>Tue, 08 May 2007 20:20:34 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[IEEE 754]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/how-to-read-the-bits-in-a-ieee-754-number/</guid>
		<description><![CDATA[That&#8217;s one of those questions you always wanted to know the answer to, but never found somebody who knew, right? Well, in C it&#8217;s pretty simple. All you have to do is to declare an union, like this: union&#123; float f; int bits; &#125; This tells the compiler that both f and bits should be [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s one of those questions you always wanted to know the answer to, but never found somebody who knew, right? <img src='http://www.strainu.ro/site/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Well, in C it&#8217;s pretty simple. All you have to do is to declare an union, like this:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">union</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #993333;">float</span> f<span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> bits<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>This tells the compiler that both <strong>f</strong> and <strong>bits</strong> should be hold in the same memory zone. This is pretty useful to save some memory, if you know for sure that you wown&#8217;t need f and bits in the same time.</p>
<p>As a side effect, if you write a value in <strong>f</strong> then read <strong>bits</strong>, you will have all the bits represented in the <a href="http://en.wikipedia.org/wiki/IEEE_754">IEEE 754</a> standard. Now you can use bit operations (&amp; , | , ^) with your number, you can extract the different parts of the number, etc. Do keep in mind that this is bad programming practice.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fhow-to-read-the-bits-in-a-ieee-754-number%2F&amp;t=How%20to%20read%20the%20bits%20in%20a%20IEEE%20754%20number%3F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=How%20to%20read%20the%20bits%20in%20a%20IEEE%20754%20number%3F%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fhow-to-read-the-bits-in-a-ieee-754-number%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fhow-to-read-the-bits-in-a-ieee-754-number%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=How%20to%20read%20the%20bits%20in%20a%20IEEE%20754%20number%3F&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fhow-to-read-the-bits-in-a-ieee-754-number%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fhow-to-read-the-bits-in-a-ieee-754-number%2F&amp;title=How%20to%20read%20the%20bits%20in%20a%20IEEE%20754%20number%3F&amp;bodytext=That%27s%20one%20of%20those%20questions%20you%20always%20wanted%20to%20know%20the%20answer%20to%2C%20but%20never%20found%20somebody%20who%20knew%2C%20right%3F%20%3AP%0D%0A%0D%0AWell%2C%20in%20C%20it%27s%20pretty%20simple.%20All%20you%20have%20to%20do%20is%20to%20declare%20an%20union%2C%20like%20this%3A%0D%0A%0D%0Aunion%7B%0D%0Afloat%20f%3B%0D%0Aint%20bits%3B%0D%0A%7D%0D%0A%0D%0AThis%20tell" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fhow-to-read-the-bits-in-a-ieee-754-number%2F&amp;title=How%20to%20read%20the%20bits%20in%20a%20IEEE%20754%20number%3F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/how-to-read-the-bits-in-a-ieee-754-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macros using do{}while(0);</title>
		<link>http://www.strainu.ro/programming/c/macros-using-dowhile0/</link>
		<comments>http://www.strainu.ro/programming/c/macros-using-dowhile0/#comments</comments>
		<pubDate>Fri, 04 May 2007 09:10:47 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[kernel]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/macros-using-dowhile0/</guid>
		<description><![CDATA[If you ever had the chance to look in the Linux kernel sources, you might have seen macros defined like this: #define foo(params) \ do{ \ &#160; &#160; //instructions \ }while(0) This basicly means that the code is executed exactly once, so the first idea is that do{}while(0); is useless. In fact, there are a [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever had the chance to look in the Linux kernel sources, you might have seen macros defined like this:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define foo(params) \<br />
do{ \<br />
&nbsp; &nbsp; //instructions \<br />
}while(0)</span></div></div>
<p>This basicly means that the code is executed exactly once, so the first idea is that <em>do{}while(0);</em> is useless.<br />
In fact, there are a number of reasons for writing the macros this way:</p>
<ul>
<li>Empty statements give warnings from the compilers, so rather than writing
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define FOO</span></div></div>
<p>you might want to write</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define FOO do{}while(0)</span></div></div>
</li>
<li> It gives you a basic block in which to declare local variables. You could simply use curly brackets, but this could cause serious problems in conditional statements. Let&#8217;s take the following example:
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define exch(a,b) {int t; t = a; a = b; b = t;}</span></div></div>
<p>You then use the macro in the following code:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>a <span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; exch<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; ready <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span></div></div>
<p>This is what the copiler will get:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>a <span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> t<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; t <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; a<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; ready <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span></div></div>
<p>This is interpreted as an <strong>if</strong> statement whithout <strong>else</strong> and you will get an error like <em>&#8220;else without matching if&#8221;</em>. However, if you write the macro like this:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define exch(a,b) do{int t; t = a; a = b; b = t;}while(0)</span></div></div>
<p>the code will behave as expected.</a></code></a></code></li>
</ul>
<p>You can find more informations about this in the <a href="http://kernelnewbies.org/FAQ/DoWhile0" target="_blank">Kernelnewbies FAQ</a>.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F&amp;t=Macros%20using%20do%7B%7Dwhile%280%29%3B" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Macros%20using%20do%7B%7Dwhile%280%29%3B%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Macros%20using%20do%7B%7Dwhile%280%29%3B&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F&amp;title=Macros%20using%20do%7B%7Dwhile%280%29%3B&amp;bodytext=If%20you%20ever%20had%20the%20chance%20to%20look%20in%20the%20Linux%20kernel%20sources%2C%20you%20might%20have%20seen%20macros%20defined%20like%20this%3A%0D%0A%0D%0A%23define%20foo%28params%29%20%5C%0D%0Ado%7B%20%5C%0D%0A%20%20%20%20%2F%2Finstructions%20%5C%0D%0A%7Dwhile%280%29%0D%0AThis%20basicly%20means%20that%20the%20code%20is%20executed%20exactly%20once%2C%20so%20the%20first%20id" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F&amp;title=Macros%20using%20do%7B%7Dwhile%280%29%3B" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/macros-using-dowhile0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

