<?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>Defective Semantics &#187; Uncategorized</title>
	<atom:link href="http://scarff.id.au/blog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://scarff.id.au</link>
	<description>Dean Scarff's perpetual struggle with technology, and other anecdotes</description>
	<lastBuildDate>Sun, 05 Sep 2010 04:34:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>C multi-character character constants</title>
		<link>http://scarff.id.au/blog/2009/c-multi-character-character-constants/</link>
		<comments>http://scarff.id.au/blog/2009/c-multi-character-character-constants/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 03:24:07 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[gcc]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=271</guid>
		<description><![CDATA[<pre class="codeblock c">
long x = '\xde\xad\xbe\xef'; // yes, single quotes
</pre>
<p>Surprisingly (to me at least), this is valid ISO 9899:1999 C.  It compiles without warning under gcc with <code>-Wall</code>, and a &#8220;multi-character character constant&#8221; warning with <code>-pedantic</code>.</p>
<p>According to the standard (§6.4.4.4.10),</p>
<blockquote><p>The value of an integer character constant containing more than one character (e.g., <code>'ab'</code>), [...] is implementation-defined.</p></blockquote>
<p>A bit of experimentation shows that gcc stores the leftmost character in the literal as the most-significant byte in the integer.  But is this a reliable behavior in other common compilers?  It&#8217;s a cool little piece of esoteric C syntax, but I&#8217;m guessing nobody interested in portable code should be using it when an integer constant works just as well.</p>
]]></description>
			<content:encoded><![CDATA[<pre class="codeblock c">
long x = '\xde\xad\xbe\xef'; // yes, single quotes
</pre>
<p>Surprisingly (to me at least), this is valid ISO 9899:1999 C.  It compiles without warning under gcc with <code>-Wall</code>, and a &#8220;multi-character character constant&#8221; warning with <code>-pedantic</code>.</p>
<p>According to the standard (§6.4.4.4.10),</p>
<blockquote><p>The value of an integer character constant containing more than one character (e.g., <code>'ab'</code>), [...] is implementation-defined.</p></blockquote>
<p>A bit of experimentation shows that gcc stores the leftmost character in the literal as the most-significant byte in the integer.  But is this a reliable behavior in other common compilers?  It&#8217;s a cool little piece of esoteric C syntax, but I&#8217;m guessing nobody interested in portable code should be using it when an integer constant works just as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2009/c-multi-character-character-constants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
