<?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>JB Enterprises – Johan Bezem &#187; General development</title>
	<atom:link href="http://www.bezem.de/category/general-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bezem.de</link>
	<description>Development &#38; Project Management</description>
	<lastBuildDate>Tue, 24 Jan 2012 18:22:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Finally: A list of C (and C++) keywords including C11 (and C++11)</title>
		<link>http://www.bezem.de/2012/01/finally-a-list-of-c-and-c-keywords-including-c11-and-c11/</link>
		<comments>http://www.bezem.de/2012/01/finally-a-list-of-c-and-c-keywords-including-c11-and-c11/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 18:22:17 +0000</pubDate>
		<dc:creator>Johan Bezem</dc:creator>
				<category><![CDATA[C Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[c11]]></category>
		<category><![CDATA[keyword]]></category>
		<category><![CDATA[standard]]></category>

		<guid isPermaLink="false">http://www.bezem.de/?p=370</guid>
		<description><![CDATA[A list of C and C++ keywords and their origins, to be found in my <a href="http://www.bezem.de/pdf/ReservedWordsInC.pdf">PDF collection</a>.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while, but now I have some news: Since I didn&#8217;t receive much response to requests in <a href="http://stackoverflow.com/q/8139659/1029106">StackOverflow</a> nor on my blog, I decided to create such a list myself. The preliminary output can be found <a href="http://www.bezem.de/pdf/ReservedWordsInC.pdf">here</a>, as a PDF as usual. It&#8217;s version 0.4 for now, and not fully complete, but I&#8217;ve added several sources, from pre-K&#038;R to C11, and from C++ 1st edition (1985), to C++11.<br/> If you find inaccuracies, please let me know, either as a comment, or by email. I intend to bring out updated editions whenever new info warrants it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bezem.de/2012/01/finally-a-list-of-c-and-c-keywords-including-c11-and-c11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming in the C/C++ realm: Identifier names to avoid &#8211; or not?</title>
		<link>http://www.bezem.de/2009/11/programming-in-the-cc-realm-identifier-names-to-avoid-or-not/</link>
		<comments>http://www.bezem.de/2009/11/programming-in-the-cc-realm-identifier-names-to-avoid-or-not/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 20:57:24 +0000</pubDate>
		<dc:creator>Johan Bezem</dc:creator>
				<category><![CDATA[C Programming]]></category>
		<category><![CDATA[identifier name]]></category>
		<category><![CDATA[keyword]]></category>
		<category><![CDATA[standard]]></category>

		<guid isPermaLink="false">http://www.bezem.de/?p=267</guid>
		<description><![CDATA[The difficulties of finding all keywords from the C/C++ realm, to be avoided when choosing identifier names.]]></description>
			<content:encoded><![CDATA[<p>The C family of languages has been around for a while, has evolved, grown, sprouted a few branches and now provides several paths for &#8216;growth&#8217;. Starting out in the seventies, standardized in the eighties, C++ in the nineties, standardized even more recently, industry-standard variants available for embedded (C++), and new standardization efforts on the way. Wonderful!<br />
Currently, just as many times before, I&#8217;m working on a project with fairly high safety requirements, programmed in C. Not C99, but C89 with a few compiler extensions for embedded programming. Not because C++ or at least C99 is not available, but because of the inertia of legacy code, and the experience level of the (otherwise highly skilled) developers. You don&#8217;t turn a team of experts in C into a team of experts in C++ within a few weeks, and the project&#8217;s goals take priority always.<br />
A few weeks ago I was looking at a piece of code like this:<br />
<code>ui32 calculate_difference(ui32 old, ui32 new) { ... }</code><br />
That gave me pause. Yes, it&#8217;s perfectly OK for C89, even C99 will not complain. But do I really want to use a C++ keyword in my C code? If ever I get to move to C++, my code <strong>must</strong> break!<br />
Having been a brief and passing guest at the <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/meetings">C++ WG21 July 2009 meeting in Frankfurt</a>, I started off on some research. (This list is just for illustration, not for completeness)</p>
<ul>
<li>An interesting keyword from the old days has been forgotten since C89: <code>entry</code></li>
<li>C89 introduced a new keyword <code>void</code></li>
<li>AMD1 introduced some new semi-keywords: <code>or_eq</code>, <code>and_eq</code>. These are not keywords in the pure sense, but you might still want to avoid them as identifier names</li>
<li>C99 added at least one more: <code>restrict</code></li>
<li>C++ adds a whole army of keywords: <code>static_cast</code>, <code>template</code>, <code>class</code></li>
<li>The coming C/C++ standards will add several more: <code>_Complex</code>, <code>_Imaginary</code></li>
</ul>
<p>So I&#8217;m now trying to find out answers to the following question: What identifier names would I want to avoid in my code, considering the vast realm of C/C++ language variants and dialects. So I started off with the keywords of all standards; then I looked into the coming standards, then I looked at the might-be keywords, packaged as macros, like complex, imaginary, decimal64, etc. The list grew, I lost my overview, however slim it had been, and I didn&#8217;t even start on the various (Standard!) libraries!<br />
I&#8217;m now starting on a more structured approach. A <a href="https://twitter.com/LintTweets">quick tweet</a> didn&#8217;t get me any response. Many overviews on the net present parts, but nothing comprehensive as far as I&#8217;ve seen, so I guess I&#8217;ll have to roll my own.<br />
If you happen to know a source of information on this, please do let me know, either as comment, or by email. I&#8217;d be more than interested.<br />
And whether you do or don&#8217;t, you&#8217;re welcome to come back here occasionally, as I&#8217;ll be reporting my findings.<br />
Happy coding!</p>
<p>Johan</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bezem.de/2009/11/programming-in-the-cc-realm-identifier-names-to-avoid-or-not/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bizarre switch statement in C</title>
		<link>http://www.bezem.de/2009/11/bizarre-switch-statement-in-c/</link>
		<comments>http://www.bezem.de/2009/11/bizarre-switch-statement-in-c/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 05:25:47 +0000</pubDate>
		<dc:creator>Johan Bezem</dc:creator>
				<category><![CDATA[General development]]></category>
		<category><![CDATA[C programming bizarre]]></category>
		<category><![CDATA[static syntax checking]]></category>

		<guid isPermaLink="false">http://www.bezem.de/?p=256</guid>
		<description><![CDATA[An example of what can be legally done in C illustrated in form of a rather bizarre switch-statement.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been in my &#8220;Bizarre C&#8221; box for many years. Things you may want or need to know about, but never would want to duplicate.</p>
<p>Currently, I am researching for a new publication, maybe a PDF document, maybe a course, on the nooks an crannies of the C programming language. And I&#8217;m finding some abstruse samples, I can tell you.</p>
<p>But one example I found most bizarre at the time (around 1990), and which still is among my favorites to flabbergast experienced C programmers, I found in the best C programming reference I&#8217;ve known to date: &#8220;<a href="http://www.amzn.com/013089592X">C &#8211; A Reference Manual</a>&#8221; by Samuel P. Harbison and Guy L. Steele (see also the <a href="http://www.careferencemanual.com/">book&#8217;s website</a>).</p>
<p>Imagine a calculation depending on certain numbers being prime or not. If the routine gets a prime parameter it executes one routine, if the parameter is not prime, another. Like this:<br />
<code>if (is_prime(a))<br />
Â·Â·process_prime(a);<br />
else<br />
Â·Â·process_nonprime(a);</code><br />
The <code>if</code>-statement is just that, a statement, a composite statement.<br />
A <code>switch</code>-statement is composed of a <code>switch</code> keyword, the value on which to operate, and a, possibly composite, statement. It could be our <code>if</code>-statement, if we so choose. However, without any <code>case</code>/<code>default</code>-labels, the <code>switch</code>-statement would just jump over the statement so specified, effectively doing nothing. To remedy that, we put the <code>default</code>-label before the <code>if</code>-statement:<br />
<code>switch (a)<br />
Â·Â·default:<br />
Â·Â·Â·Â·if (is_prime(a))<br />
Â·Â·Â·Â·Â·Â·process_prime(a);<br />
Â·Â·Â·Â·else<br />
Â·Â·Â·Â·Â·Â·process_nonprime(a);</code><br />
This code already looks strange, but it is functionally equivalent to the <code>if</code>-statement by itself.<br />
If we now imagine the function <code>is_prime(a)</code> to be very expensive, it would make sense to take a shortcut around that function wherever possible. And if 99% of the values the variable <code>a</code> can have lie between 2 and 10 inclusive, it definitely would make sense to circumvent the <code>is_prime()</code> function, since we know the primeness of those values without calculation:<br />
<code>switch (a)<br />
Â·Â·default:<br />
Â·Â·Â·Â·if (is_prime(a))<br />
Â·Â·case 2: case 3: case 5: case 7:<br />
Â·Â·Â·Â·Â·Â·process_prime(a);<br />
Â·Â·Â·Â·else<br />
Â·Â·case 4: case 6: case 8: case 9: case 10:<br />
Â·Â·Â·Â·Â·Â·process_nonprime(a);</code><br />
To understand why this is correct C, we need to realize that <code>case</code>-labels belonging to a <code>switch</code>-statement can be positioned anywhere within the boundaries of the composite statement belonging to the <code>switch</code>. In our case, this means until the semicolon after the <code>process_nonprime(a)</code> statement.<br />
It works as follows:</p>
<ul>
<li>If <code>a</code> is 3 upon execution of the <code>switch</code>, the label <code>case 3:</code> is where execution continues after determining the value of <code>a</code> to be three, jumping into the middle of the <code>if</code>-statement and calling the function <code>process_prime</code> with a parameter 3. After execution of that function, the <code>if</code>-statement is terminated, terminating the enclosing <code>switch</code>-statement at the same time.</li>
<li>If <code>a</code> is 8 upon execution of the <code>switch</code>, the label <code>case 8:</code> is where execution continues after determining the value of <code>a</code> to be eight, jumping into the middle of the <code>if</code>-statement and calling the function <code>process_nonprime</code> with a parameter 8. After execution of that function, the <code>if</code>-statement is terminated, terminating the enclosing <code>switch</code>-statement at the same time.</li>
<li>If <code>a</code> is 29 upon execution of the <code>switch</code>, the label <code>default:</code> is where execution continues after determining that no known value is to be processed, executing the <code>if</code>-statement from its beginning. Depending on the value of <code>a</code> (29 in this case) the <code>if</code>-condition determines which of the two alternative functions to call, just like a normal <code>if</code>-statement.</li>
</ul>
<p>I can only agree with Sam Harbison and Guy Steele: &#8220;This is frankly the most bizarre switch statement we have ever seen that still has pretenses to being purposeful.&#8221;<br />
Would you want the nuclear reactor around the corner being coded like this?<br />
Happy coding!</p>
<p>Johan</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bezem.de/2009/11/bizarre-switch-statement-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why 32768 isn&#8217;t always the same as 0&#215;8000</title>
		<link>http://www.bezem.de/2009/03/why-32768-ist-always-the-same-as-0x8000/</link>
		<comments>http://www.bezem.de/2009/03/why-32768-ist-always-the-same-as-0x8000/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 19:35:34 +0000</pubDate>
		<dc:creator>Johan Bezem</dc:creator>
				<category><![CDATA[General development]]></category>
		<category><![CDATA[PC Lint / FlexeLint]]></category>
		<category><![CDATA[QAC]]></category>
		<category><![CDATA[Lint]]></category>
		<category><![CDATA[static syntax checking]]></category>

		<guid isPermaLink="false">http://www.bezem.de/?p=226</guid>
		<description><![CDATA[Contrary to intuition, the C constants &#8217;32768&#8242; and &#8217;0&#215;8000&#8242; have an identical representation (0&#215;8000), but possibly different types in C. If you consider a processor with a 16-bit int type, and a 32-bit long type, 32768 is considered long, whereas 0&#215;8000 (and the octal variant 0100000) is considered &#8216;unsigned int&#8217;. If you feel the need, [...]]]></description>
			<content:encoded><![CDATA[<p>Contrary to intuition, the C constants &#8217;32768&#8242; and &#8217;0&#215;8000&#8242; have an<br />
identical representation (0&#215;8000), but possibly different types in C.<br />
If you consider  a processor with a 16-bit int type, and a 32-bit long<br />
type, 32768 is considered long, whereas 0&#215;8000 (and the octal variant<br />
0100000) is considered &#8216;unsigned int&#8217;.</p>
<p>If you feel the need, check the C standard at<br />
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf, page 55 at the<br />
bottom, and the table at page 56. (look at Harbison &amp; Steele, 5th edition, and look at section 2.7.1 page 24ff).</p>
<p>Normally, there is no problem when using such values, since the<br />
representations are identical.<br />
However, consider this small example:</p>
<pre>#define C_DECIMAL     32768
#define C_HEXADECIMAL 0x8000

void main(int argc, char *argv[])
{
  volatile long long_dec = ((long)~C_DECIMAL);
  volatile long long_hex = ((long)~C_HEXADECIMAL);

  return;
}</pre>
<p>When C_DECIMAL is considered long, the negation will invert 32 bits,<br />
resulting in a representation 0xFFFF7FFF with type &#8216;long&#8217;; the cast is<br />
superfluous.<br />
When C_HEXADECIMAL is considered &#8216;unsigned int&#8217;, the negation will invert<br />
16 bits, resulting in a representation 0x7FFF with type &#8216;unsigned int&#8217;;<br />
the cast will then zero-extend to a &#8216;long&#8217; value of 0x00007FFF.</p>
<p>Checking with a 16-bit integer compiler (CW7.1 ColdFire using &#8216;-intsize 2&#8242;):</p>
<pre>0x00000000                    _main:
;                             main:
0x00000000  0x4E560000               link     a6,#0
0x00000004  0x518F                   subq.l   #8,a7
0x00000006  0x223C<em>FFFF7FFF</em>           move.l   #-32769,d1
0x0000000C  0x2D41FFF8               move.l   d1,-8(a6)
0x00000010  0x223C<em>00007FFF</em>           move.l   #32767,d1
0x00000016  0x2D41FFFC               move.l   d1,-4(a6)
0x0000001A  0x4E5E                   unlk     a6
0x0000001C  0x4E75                   rts</pre>
<p>For those of you who do not know how to read assembler code I have made the differing values <em>italic</em>. So the compiler confirms the difference in behavior, and this is not a compiler error.</p>
<p>Lucky you if you have Lint to warn you. (Yes, I know, other tools will too, if you let them&#8230;)</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bezem.de/2009/03/why-32768-ist-always-the-same-as-0x8000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two new articles: Physical Architecture and Coding Conventions</title>
		<link>http://www.bezem.de/2009/02/two-new-articles-physical-architecture-and-coding-conventions/</link>
		<comments>http://www.bezem.de/2009/02/two-new-articles-physical-architecture-and-coding-conventions/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 19:45:52 +0000</pubDate>
		<dc:creator>Johan Bezem</dc:creator>
				<category><![CDATA[General development]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://www.bezem.de/?p=200</guid>
		<description><![CDATA[I just added two articles, again, the basics of which have been written some time ago, but now I revamped them and put them on the website. And since the number of articles (or: white papers) has grown, I have dedicated a new page to these &#8220;white papers&#8221;. I now express my opinion on physical [...]]]></description>
			<content:encoded><![CDATA[<p>I just added two articles, again, the basics of which have been written some time ago, but now I revamped them and put them on the website.<br />
And since the number of articles (or: white papers) has grown, I have dedicated a new page to these &#8220;white papers&#8221;.</p>
<p>I now express my opinion on physical architecture (in contrast to the logical software architecture everyone learns when trying to learn programming), and on the almost religious topic of coding conventions. Have a look at the new <a href="http://www.bezem.de/en/whitepapers/">white paper page</a>!</p>
<p>Johan</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bezem.de/2009/02/two-new-articles-physical-architecture-and-coding-conventions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

