<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Inside Out &#187; const</title>
	<atom:link href="http://belhob.wordpress.com/tag/const/feed/" rel="self" type="application/rss+xml" />
	<link>http://belhob.wordpress.com</link>
	<description>Dare to Dream. If u can Dream, U can make the Dreams come true.</description>
	<lastBuildDate>Tue, 18 Mar 2008 04:50:37 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='belhob.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/470703d04704b4b85b671f6fac3eb443?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Inside Out &#187; const</title>
		<link>http://belhob.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://belhob.wordpress.com/osd.xml" title="Inside Out" />
		<item>
		<title>The ‘C’ test. Part &#8211; XVI</title>
		<link>http://belhob.wordpress.com/2007/12/01/the-%e2%80%98c%e2%80%99-test-part-xvi/</link>
		<comments>http://belhob.wordpress.com/2007/12/01/the-%e2%80%98c%e2%80%99-test-part-xvi/#comments</comments>
		<pubDate>Sat, 01 Dec 2007 09:15:39 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[appalling constructs]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/12/01/the-%e2%80%98c%e2%80%99-test-part-xvi/</guid>
		<description><![CDATA[Obscure syntax

16. &#8216;C&#8217; allows some appalling constructs. Is this construct legal, and if so what does this code do?
int a = 5, b = 7, c;
c = a+++b;
This question is intended to be a lighthearted end to the quiz, as, believe it or not, this is perfectly legal syntax. The question is how does the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=97&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/100px-Example.svg.png"><img ALIGN="right" HEIGHT="100" WIDTH="100" VSPACE="15" HSPACE="15" BORDER="0" SRC="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/100px-Example.svg.png" /></a><strong>Obscure syntax</strong></p>
<p><strong><br />
16. &#8216;C&#8217; allows some appalling constructs. Is this construct legal, and if so what does this code do?</strong></p>
<p><em><strong>int a = 5, b = 7, c;<br />
c = a+++b;</strong></em></p>
<p>This question is intended to be a lighthearted end to the quiz, as, believe it or not, this is perfectly legal syntax. The question is how does the compiler treat it? Those poor compiler writers actually debated this issue, and came up with the &#8220;maximum munch&#8221; rule, which stipulates that the compiler should bite off as big (and legal) a chunk as it can. Hence, this code is treated as:</p>
<p><em><strong>c = a++ + b;</strong></em></p>
<p><strong><em>Thus, after this code is executed, a = 6, b = 7, and c = 12.</em></strong></p>
<p>If you knew the answer, or guessed correctly, well done. If you didn&#8217;t know the answer then I wouldn&#8217;t consider this to be a problem. I find the greatest benefit of this question is that it is good for stimulating questions on coding styles, the value of code reviews, and the benefits of using lint.</p>
<p>Well folks, there you have it. That was my version of the C test. I hope you had as much fun taking it as I had writing it. If you think the test is a good test, then by all means use it in your recruitment. Who knows, I may get lucky in a year or two and end up being on the receiving end of my own work.</p>
<p><strong> Links:</strong></p>
<p>for <em><strong>&#8220;The ‘C’ test. Part &#8211; I&#8221; </strong></em> to  <strong><em>&#8220;The ‘C’ test. Part &#8211; XVI&#8221;</em></strong></p>
<p><a HREF="http://www.embedded.com/2000/0005/0005feat2.htm">http://www.embedded.com/2000/0005/0005feat2.htm</a></p>
<p><a HREF="http://www.embedded.com/98/9811/9811fe3.htm ">http://www.embedded.com/98/9811/9811fe3.htm </a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/97/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/97/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=97&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/12/01/the-%e2%80%98c%e2%80%99-test-part-xvi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; XV</title>
		<link>http://belhob.wordpress.com/2007/11/30/the-%e2%80%98c%e2%80%99-test-part-xv/</link>
		<comments>http://belhob.wordpress.com/2007/11/30/the-%e2%80%98c%e2%80%99-test-part-xv/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 18:32:20 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[typedef]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/30/the-%e2%80%98c%e2%80%99-test-part-xv/</guid>
		<description><![CDATA[Typedef
15. Typedef is frequently used in C to declare synonyms for pre-existing data types. It is also possible to use the preprocessor to do something similar. For instance, consider the following code fragment:
#define dPS  struct s *
typedef  struct s * tPS;
The intent in both cases is to define dPS and tPS to be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=96&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><img SRC="http://www.w3.org/XML/1998/06/graphics-v21/typedef.gif" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="324" HEIGHT="240" ALIGN="left" /><strong>Typedef</strong><br />
<strong>15. Typedef is frequently used in C to declare synonyms for pre-existing data types. It is also possible to use the preprocessor to do something similar. For instance, consider the following code fragment:</strong></p>
<p><strong><em>#define dPS  struct s *<br />
typedef  struct s * tPS;</em></strong></p>
<p>The intent in both cases is to define <em><strong>dPS</strong></em> and <em><strong>tPS</strong></em> to be pointers to structure <em><strong>s</strong></em>. Which method, if any, is preferred and why?</p>
<p>This is a very subtle question, and anyone who gets it right (for the right reason) is to be congratulated or condemned (&#8220;get a life&#8221; springs to mind). The answer is the typedef is preferred. Consider the declarations:</p>
<p><strong><em>dPS p1,p2;<br />
tPS p3,p4;</em></strong></p>
<p>The first expands to:</p>
<p><em><strong>struct s * p1, p2;</strong></em></p>
<p>which defines <strong><em>p1</em></strong> to be a pointer to the structure and <strong><em>p2</em></strong> to be an actual structure, which is probably not what you wanted. The second example correctly defines<em> </em><strong><em>p3</em></strong> and<em> </em><strong><em>p4</em></strong> to be pointers<strong> </strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/96/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/96/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=96&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/30/the-%e2%80%98c%e2%80%99-test-part-xv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; XIV</title>
		<link>http://belhob.wordpress.com/2007/11/29/the-%e2%80%98c%e2%80%99-test-part-xiv/</link>
		<comments>http://belhob.wordpress.com/2007/11/29/the-%e2%80%98c%e2%80%99-test-part-xiv/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 18:35:19 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Dynamic memory allocation]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/29/the-%e2%80%98c%e2%80%99-test-part-xiv/</guid>
		<description><![CDATA[Dynamic memory allocation
14. Although not as common as in non-embedded computers, embedded systems do still dynamically allocate memory from the heap. What are the problems with dynamic memory allocation in embedded systems?
Here, I expect the user to mention memory fragmentation, problems with garbage collection, variable execution time, and so on. This topic has been covered [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=95&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://img.sparknotes.com/figures/E/ecdf52f6d8fc18c1bf30cea64cd0ed1e/dynptr1.gif"><img SRC="http://img.sparknotes.com/figures/E/ecdf52f6d8fc18c1bf30cea64cd0ed1e/dynptr1.gif" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="298" HEIGHT="220" ALIGN="right" /></a><strong>Dynamic memory allocation</strong></p>
<p><strong>14. Although not as common as in non-embedded computers, embedded systems do still dynamically allocate memory from the heap. What are the problems with dynamic memory allocation in embedded systems?</strong></p>
<p>Here, I expect the user to mention memory fragmentation, problems with garbage collection, variable execution time, and so on. This topic has been covered extensively in ESP , mainly by P.J. Plauger. His explanations are far more insightful than anything I could offer here, so go and read those back issues! Having lulled the candidate into a sense of false security, I then offer up this tidbit:</p>
<p><strong><br />
What does the following code fragment output and why?</strong></p>
<p><em><strong>char *ptr;<br />
if ((ptr = (char *)malloc(0)) ==NULL)</strong></em></p>
<p><em><strong><em><strong>puts(&#8220;Got a null pointer&#8221;);</strong></em><em><strong><br />
else<br />
puts(&#8220;Got a valid pointer&#8221;);</strong></em></strong></em></p>
<p>This is a fun question. I stumbled across this only recently when a colleague of mine inadvertently passed a value of 0 to malloc and got back a valid pointer! That is, the above code will output &#8220;Got a valid pointer.&#8221; I use this to start a discussion on whether the interviewee thinks this is the correct thing for the library routine to do. Getting the right answer here is not nearly as important as the way you approach the problem and the rationale for your decision.</p>
<p ALIGN="right"><strong>…to be continued </strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/95/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/95/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=95&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/29/the-%e2%80%98c%e2%80%99-test-part-xiv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; XIII</title>
		<link>http://belhob.wordpress.com/2007/11/28/the-%e2%80%98c%e2%80%99-test-part-xiii/</link>
		<comments>http://belhob.wordpress.com/2007/11/28/the-%e2%80%98c%e2%80%99-test-part-xiii/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 18:35:56 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[code fragment]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[Compliment of Zero]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[importance of word length on a computer]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/28/the-%e2%80%98c%e2%80%99-test-part-xiii/</guid>
		<description><![CDATA[13. Comment on the following code fragment.
unsigned int zero = 0;
unsigned int compzero = 0xFFFF;
/*1&#8217;s complement of zero */
On machines where an int is not 16 bits, this will be incorrect. It should be coded:
unsigned int compzero = ~0;
This question really gets to whether the candidate understands the importance of word length on a computer. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=94&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://www.technikum29.de/shared/photos/rechnertechnik/speichermedien/kernspeicher.jpg"><img ALIGN="left" HEIGHT="208" WIDTH="278" VSPACE="15" HSPACE="15" BORDER="0" SRC="http://www.technikum29.de/shared/photos/rechnertechnik/speichermedien/kernspeicher.jpg" /></a><strong>13. Comment on the following code fragment.</strong></p>
<p><em><strong>unsigned int zero = 0;<br />
unsigned int compzero = 0xFFFF;<br />
/*1&#8217;s complement of zero */</strong></em></p>
<p>On machines where an int is not 16 bits, this will be incorrect. It should be coded:</p>
<p><strong><em>unsigned int compzero = ~0;</em></strong></p>
<p>This question really gets to whether the candidate understands the importance of word length on a computer. In my experience, good embedded programmers are critically aware of the underlying hardware and its limitations, whereas computer programmers tend to dismiss the hardware as a necessary annoyance.</p>
<p>By this stage, candidates are either completely demoralized-or they&#8217;re on a roll and having a good time. If it&#8217;s obvious that the candidate isn&#8217;t very good, then the test is terminated at this point. However, if the candidate is doing well, then I throw in these supplemental questions. These questions are hard, and I expect that only the very best candidates will do well on them. In posing these questions, I&#8217;m looking more at the way the candidate tackles the problems, rather than the answers.</p>
<p ALIGN="right"><strong>…to be continued </strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/94/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/94/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=94&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/28/the-%e2%80%98c%e2%80%99-test-part-xiii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; XII</title>
		<link>http://belhob.wordpress.com/2007/11/27/the-%e2%80%98c%e2%80%99-test-part-xii/</link>
		<comments>http://belhob.wordpress.com/2007/11/27/the-%e2%80%98c%e2%80%99-test-part-xii/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 18:31:58 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[Code examples]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[integer promotion rules]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/27/the-%e2%80%98c%e2%80%99-test-part-xii/</guid>
		<description><![CDATA[Code examples
12. What does the following code output and why?
void foo(void)
{
           unsigned int a = 6;
           int b = -20;
          (a+b &#62; 6) ? puts(&#8220;&#62; 6&#8243;) : puts(&#8220;&#60;= 6&#8243;);
}

This question tests whether you understand the integer promotion rules in C-an area that I find is very poorly understood by many developers.
Anyway, the answer is that this outputs &#8220;&#62; 6.&#8221; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=93&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://mwolson.risnerolson.org/static/pics/anime/serial_experiments_lain/c_code.png"><img SRC="http://mwolson.risnerolson.org/static/pics/anime/serial_experiments_lain/c_code.png" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="256" HEIGHT="192" ALIGN="right" /></a><strong>Code examples</strong></p>
<p><strong>12. What does the following code output and why?</strong></p>
<p><strong><em>void foo(void)</em></strong><strong><em><br />
</em></strong><strong><em>{</em></strong><strong><em><br />
</em></strong><strong><em>           unsigned int a = 6;</em></strong><strong><em><br />
</em></strong><strong><em>           int b = -20;</em></strong><strong><em><br />
</em></strong><strong><em>          (a+b &gt; 6) ? puts(&#8220;&gt; 6&#8243;) : puts(&#8220;&lt;= 6&#8243;);</em></strong></p>
<p><strong><em>}</em></strong><strong><br />
</strong></p>
<p>This question tests whether you understand the integer promotion rules in C-an area that I find is very poorly understood by many developers.</p>
<p>Anyway, the answer is that this outputs &#8220;&gt; 6.&#8221; The reason for this is that expressions involving signed and unsigned types have all operands promoted to unsigned types. Thus -20 becomes a very large positive integer and the expression evaluates to greater than 6. This is a very important point in embedded systems where unsigned data types should be used frequently (see Reference 2).</p>
<p><strong>If you get this one wrong, you are perilously close to not getting the job.</strong></p>
<p ALIGN="right"><strong>…to be continued</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/93/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/93/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=93&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/27/the-%e2%80%98c%e2%80%99-test-part-xii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; XI</title>
		<link>http://belhob.wordpress.com/2007/11/26/the-%e2%80%98c%e2%80%99-test-part-xi/</link>
		<comments>http://belhob.wordpress.com/2007/11/26/the-%e2%80%98c%e2%80%99-test-part-xi/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 05:30:40 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[interrupt service routine]]></category>
		<category><![CDATA[interrupts]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/26/the-%e2%80%98c%e2%80%99-test-part-xi/</guid>
		<description><![CDATA[Interrupts
11. Interrupts are an important part of embedded systems. Consequently, many compiler vendors offer an extension to standard C to support interrupts. Typically, this new keyword is __interrupt. The following code uses __interrupt to define an interrupt service routine (ISR). Comment on the code.
__interrupt double compute_area
(double
radius)
{
double area = PI * radius *
radius;
printf(&#8220;\nArea = %f&#8221;, area);
return [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=92&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://www.codeguru.com/dbfiles/get_image.php?id=8035&amp;lbl=NTSYSTEMCALLSIMAGE3_JPG&amp;ds=20040826"><img SRC="http://www.codeguru.com/dbfiles/get_image.php?id=8035&amp;lbl=NTSYSTEMCALLSIMAGE3_JPG&amp;ds=20040826" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="282" HEIGHT="196" ALIGN="left" /></a><strong>Interrupts</strong><br />
<strong>11. Interrupts are an important part of embedded systems. Consequently, many compiler vendors offer an extension to standard C to support interrupts. Typically, this new keyword is __interrupt. The following code uses __interrupt to define an interrupt service routine (ISR). Comment on the code.</strong></p>
<p><em><strong>__interrupt double compute_area<br />
(double<br />
radius)<br />
{<br />
double area = PI * radius *<br />
radius;<br />
printf(&#8220;\nArea = %f&#8221;, area);<br />
return area;<br />
}</strong></em></p>
<p>This function has so much wrong with it, it&#8217;s hard to know where to start:</p>
<ul>
<li>ISRs cannot return a value. If you don&#8217;t understand this, you aren&#8217;t hired</li>
</ul>
<ul>
<li>ISRs cannot be passed parameters. See the first item for your employment prospects if you missed this</li>
</ul>
<ul>
<li>On many processors/compilers, floating-point operations are not necessarily re-entrant. In some cases one needs to stack additional registers. In other cases, one simply cannot do floating point in an ISR. Furthermore, given that a general rule of thumb is that ISRs should be short and sweet, one wonders about the wisdom of doing floating-point math here</li>
</ul>
<ul>
<li>In a vein similar to the third point, printf() often has problems with reentrancy and performance. If you missed points three and four, I wouldn&#8217;t be too hard on you. Needless to say, if you got these last two points, your employment prospects are looking better and better</li>
</ul>
<p ALIGN="right"><strong>…to be continued</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/92/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/92/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=92&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/26/the-%e2%80%98c%e2%80%99-test-part-xi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; X</title>
		<link>http://belhob.wordpress.com/2007/11/25/the-%e2%80%98c%e2%80%99-test-part-x/</link>
		<comments>http://belhob.wordpress.com/2007/11/25/the-%e2%80%98c%e2%80%99-test-part-x/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 18:32:14 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[accessing fixed memory locations]]></category>
		<category><![CDATA[ANSI]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/25/the-%e2%80%98c%e2%80%99-test-part-x/</guid>
		<description><![CDATA[Accessing fixed memory locations
10. Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0&#215;67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.
This problem tests [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=91&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://webster.cs.ucr.edu/AoA/Windows/HTML/images/MemoryAccessandOrg14.gif"><img SRC="http://webster.cs.ucr.edu/AoA/Windows/HTML/images/MemoryAccessandOrg14.gif" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="285" HEIGHT="240" ALIGN="right" /></a><strong><em>Accessing fixed memory locations</em></strong></p>
<p><strong>10. Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0&#215;67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.</strong></p>
<p>This problem tests whether you know that it is legal to typecast an integer to a pointer in order to access an absolute location. The exact syntax varies depending upon one&#8217;s style. However, I would typically be looking for something like this:</p>
<p><strong>int *ptr;<br />
ptr = (int *)0&#215;67a9;<br />
*ptr = 0xaa55;</strong></p>
<p>A more obscure approach is:</p>
<p><strong>*(int * const)(0&#215;67a9) = 0xaa55;</strong></p>
<p>Even if your taste runs more to the second solution, I suggest the first solution when you are in an interview situation.</p>
<p ALIGN="right"><strong>…to be continued </strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/91/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/91/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=91&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/25/the-%e2%80%98c%e2%80%99-test-part-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; IX</title>
		<link>http://belhob.wordpress.com/2007/11/24/the-%e2%80%98c%e2%80%99-test-part-ix/</link>
		<comments>http://belhob.wordpress.com/2007/11/24/the-%e2%80%98c%e2%80%99-test-part-ix/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 18:30:37 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[*ptr]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[Bit Manipulations]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/24/the-%e2%80%98c%e2%80%99-test-part-ix/</guid>
		<description><![CDATA[Bit manipulation
9. Embedded systems always require the user to manipulate bits in registers or variables. Given an integer variable a, write two code fragments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified.
These are the three basic responses to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=90&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://mrccs.man.ac.uk/seminars/images/harmin.gif"><img SRC="http://mrccs.man.ac.uk/seminars/images/harmin.gif" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="241" HEIGHT="180" ALIGN="left" /></a><strong>Bit manipulation</strong><br />
<strong>9. Embedded systems always require the user to manipulate bits in registers or variables. Given an integer variable a, write two code frag</strong><strong>ments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified.</strong></p>
<p>These are the three basic responses to this question:</p>
<ul>
<li>No idea. The interviewee cannot have done any embedded systems work</li>
</ul>
<ul>
<li> Use bit fields. Bit fields are right up there with trigraphs as the most brain-dead portion of C. Bit fields are inherently non-portable across compilers, and as such guarantee that your code is not reusable. I recently had the misfortune to look at a driver written by Infineon for one of their more complex communications chips. It used bit fields and was completely useless because my compiler implemented the bit fields the other way around. The moral: never let a non-embedded person anywhere near a real piece of hardware!</li>
</ul>
<ul>
<li> Use #defines and bit masks. This is a highly portable method and is the one that should be used. My optimal solution to this problem would be:</li>
</ul>
<p>#define BIT3	(0&#215;1 &lt;&lt; 3)<br />
static int a;</p>
<p>void set_bit3(void) {<br />
a |= BIT3;<br />
}<br />
void clear_bit3(void) {<br />
a &amp;= ~BIT3;<br />
}</p>
<p>Some people prefer to define a mask together with manifest constants for the set and clear values. This is also acceptable. The element that I&#8217;m looking for is the use of manifest constants, together with the |= and &amp;= ~ constructs</p>
<p ALIGN="right"><strong>…to be continued</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/90/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/90/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=90&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/24/the-%e2%80%98c%e2%80%99-test-part-ix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; VIII</title>
		<link>http://belhob.wordpress.com/2007/11/23/the-%e2%80%98c%e2%80%99-test-part-viii/</link>
		<comments>http://belhob.wordpress.com/2007/11/23/the-%e2%80%98c%e2%80%99-test-part-viii/#comments</comments>
		<pubDate>Thu, 22 Nov 2007 18:31:52 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Keywords]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/23/the-%e2%80%98c%e2%80%99-test-part-viii/</guid>
		<description><![CDATA[Volatile
8. What does the keyword volatile mean? Give three different examples of its use.
A volatile variable is one that can change unexpectedly. Consequently, the compiler can make no assumptions about the value of the variable. In particular, the optimizer must be careful to reload the variable every time it is used instead of holding a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=89&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://www.enzyscreen.com/i1890815-3.jpg"><img SRC="http://www.enzyscreen.com/i1890815-3.jpg" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="299" HEIGHT="339" ALIGN="right" /></a><strong>Volatile<br />
8. What does the keyword volatile mean? Give three different examples of its use.</strong></p>
<p>A volatile variable is one that can change unexpectedly. Consequently, the compiler can make no assumptions about the value of the variable. In particular, the optimizer must be careful to reload the variable every time it is used instead of holding a copy in a register. Examples of volatile variables are:</p>
<ul>
<li>Hardware registers in peripherals (for example, status registers)</li>
<li> Non-automatic variables referenced within an interrupt service routine</li>
<li> Variables shared by multiple tasks in a multi-threaded application</li>
</ul>
<p>Candidates who don&#8217;t know the answer to this question aren&#8217;t hired. I consider this the most fundamental question that distinguishes between a C programmer and an embedded systems programmer. Embedded folks deal with hardware, interrupts, RTOSes, and the like. All of these require volatile variables. Failure to understand the concept of volatile will lead to disaster.</p>
<p>On the (dubious) assumption that the interviewee gets this question correct, I like to probe a little deeper to see if they really understand the full significance of volatile . In particular, I&#8217;ll ask them the following additional questions:</p>
<ul>
<li><strong>Can a parameter be both const and volatile ? Explain.<br />
</strong></li>
<li><strong>Can a pointer be volatile ? Explain.</strong><strong><br />
</strong></li>
<li><strong> What&#8217;s wrong with the following function?</strong></li>
</ul>
<p>int square(volatile int *ptr)<br />
{<br />
return *ptr * *ptr;<br />
}</p>
<p><strong>The answers are as follows:</strong></p>
<ul>
<li>Yes. An example is a read-only status register. It is volatile because it can change unexpectedly. It is const because the program should not attempt to modify it</li>
</ul>
<ul>
<li>Yes, although this is not very common. An example is when an interrupt service routine modifies a pointer to a buffer</li>
</ul>
<ul>
<li>This one is wicked. The intent of the code is to return the square of the value pointed to by *ptr . However, since *ptr points to a volatile parameter, the compiler will generate code that looks something like this:</li>
</ul>
<p>int square(volatile int *ptr)<br />
{<br />
int a,b;<br />
a = *ptr;<br />
b = *ptr;<br />
return a * b;<br />
}</p>
<p>Because it&#8217;s possible for the value of *ptr to change unexpectedly, it is possible for a and b to be different. Consequently, this code could return a number that is not a square! The correct way to code this is:</p>
<p>long square(volatile int *ptr)<br />
{<br />
int a;<br />
a = *ptr;<br />
return a * a;<br />
}</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/89/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/89/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=89&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/23/the-%e2%80%98c%e2%80%99-test-part-viii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
		<item>
		<title>The ‘C’ test. Part &#8211; VII</title>
		<link>http://belhob.wordpress.com/2007/11/22/the-%e2%80%98c%e2%80%99-test-part-vii/</link>
		<comments>http://belhob.wordpress.com/2007/11/22/the-%e2%80%98c%e2%80%99-test-part-vii/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 18:31:50 +0000</pubDate>
		<dc:creator>Bipin Gautam Taksande</dc:creator>
				<category><![CDATA[C/C++ Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA['C ' test]]></category>
		<category><![CDATA[C Questions]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Data declarations]]></category>
		<category><![CDATA[Dos & Donts]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[inadvertent coding]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://belhob.wordpress.com/2007/11/22/the-%e2%80%98c%e2%80%99-test-part-vii/</guid>
		<description><![CDATA[Const
7. What does the keyword const mean?
As soon as the interviewee says &#8220;const means constant,&#8221; I know I&#8217;m dealing with an amateur. Dan Saks has exhaustively covered const in the last year, such that every reader of ESP should be extremely familiar with what const can and cannot do for you. If you haven&#8217;t been [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=88&subd=belhob&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a HREF="http://www.paweng.com/pawcalc/manual/images/const.gif"><img SRC="http://www.paweng.com/pawcalc/manual/images/const.gif" BORDER="0" HSPACE="15" VSPACE="15" WIDTH="240" HEIGHT="240" ALIGN="left" /></a><strong>Const<br />
7. What does the keyword const mean?</strong></p>
<p>As soon as the interviewee says &#8220;const means constant,&#8221; I know I&#8217;m dealing with an amateur. Dan Saks has exhaustively covered const in the last year, such that every reader of ESP should be extremely familiar with what const can and cannot do for you. If you haven&#8217;t been reading that column, suffice it to say that const means &#8220;read-only.&#8221; Although this answer doesn&#8217;t really do the subject justice, I&#8217;d accept it as a correct answer. (If you want the detailed answer, read Saks&#8217; columns-carefully!)</p>
<p>If the candidate gets the answer correct, I&#8217;ll ask him these supplemental questions:</p>
<p><strong>What do the following declarations mean?</strong></p>
<p>const int a;<br />
int const a;<br />
const int *a;<br />
int * const a;<br />
int const * a const;</p>
<p>The first two mean the same thing, namely a is a const (read-only) integer. The third means a is a pointer to a const integer (that is, the integer isn&#8217;t modifiable, but the pointer is). The fourth declares a to be a const pointer to an integer (that is, the integer pointed to by a is modifiable, but the pointer is not). The final declaration declares a to be a const pointer to a const integer (that is, neither the integer pointed to by a, nor the pointer itself may be modified). If the candidate correctly answers these questions, I&#8217;ll be impressed. Incidentally, you might wonder why I put so much emphasis on const, since it is easy to write a correctly functioning program without ever using it. I have several reasons:</p>
<ul>
<li>The use of const conveys some very useful information to someone reading your code. In effect, declaring a parameter const tells the user about its intended usage. If you spend a lot of time cleaning up the mess left by other people, you&#8217;ll quickly learn to appreciate this extra piece of information. (Of course, programmers who use const , rarely leave a mess for others to clean up.)</li>
<li>const has the potential for generating tighter code by giving the optimizer some additional information</li>
<li>Code that uses const liberally is inherently protected by the compiler against inadvertent coding constructs that result in parameters being changed that should not be. In short, they tend to have fewer bugs</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/belhob.wordpress.com/88/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/belhob.wordpress.com/88/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/belhob.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/belhob.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/belhob.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/belhob.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/belhob.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/belhob.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/belhob.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/belhob.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/belhob.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/belhob.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=belhob.wordpress.com&blog=1054595&post=88&subd=belhob&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://belhob.wordpress.com/2007/11/22/the-%e2%80%98c%e2%80%99-test-part-vii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/67813aa08830bd31722c3ab9736fa66a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Bipin Gautam Taksande</media:title>
		</media:content>
	</item>
	</channel>
</rss>