<?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; QAC</title>
	<atom:link href="http://www.bezem.de/category/qac/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>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>
	</channel>
</rss>

