<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Why the compiler won&#8217;t let you declare a variable immediately after a case</title>
	<atom:link href="http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case</link>
	<description>The personal weblog of Peter Hosey.</description>
	<lastBuildDate>Wed, 09 May 2012 18:26:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case/comment-page-1#comment-243734</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Sat, 21 Feb 2009 15:13:43 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=929#comment-243734</guid>
		<description>JediKnil: Actually, you might very well want to jump to the top of a block, where there may be declarations.

And did you read Jeff Johnson&#039;s tweet, which I linked to? There&#039;s a very simple reason why you can&#039;t make declarations statements. The same reason applies to &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;…&lt;code&gt;while&lt;/code&gt;, and &lt;code&gt;switch&lt;/code&gt; itself. I, for one, think disallowing “&lt;code&gt;if (foo) int foo_alpha;&lt;/code&gt;” is a valuable syntax error for newcomers to the language.

A better solution may be to change the definition of labeled-statement to so that a block-item, not only a statement, follows the label. But, again, I haven&#039;t thought through any ramifications of that.</description>
		<content:encoded><![CDATA[<p>JediKnil: Actually, you might very well want to jump to the top of a block, where there may be declarations.</p>
<p>And did you read Jeff Johnson&#8217;s tweet, which I linked to? There&#8217;s a very simple reason why you can&#8217;t make declarations statements. The same reason applies to <code>for</code>, <code>while</code>, <code>do</code>…<code>while</code>, and <code>switch</code> itself. I, for one, think disallowing “<code>if (foo) int foo_alpha;</code>” is a valuable syntax error for newcomers to the language.</p>
<p>A better solution may be to change the definition of labeled-statement to so that a block-item, not only a statement, follows the label. But, again, I haven&#8217;t thought through any ramifications of that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordy/Jediknil</title>
		<link>http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case/comment-page-1#comment-243690</link>
		<dc:creator>Jordy/Jediknil</dc:creator>
		<pubDate>Sat, 21 Feb 2009 06:04:14 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=929#comment-243690</guid>
		<description>It makes sense, in a very stupid way, if you consider labeled statements /outside/ of a &lt;code&gt;switch&lt;/code&gt;. You can&#039;t label a declaration with a &lt;code&gt;goto&lt;/code&gt;-style label because there&#039;s no statement to &lt;code&gt;goto&lt;/code&gt;.

But given the common use of switch statements, this is silly. Java (among other languages, maybe C++ too, I can&#039;t remember) does the Right Thing by syntactically making declarations statements, and making sure the variables they&#039;re declaring are usable in the rest of the block.

C&#039;s &lt;code&gt;switch&lt;/code&gt; is ugly anyways. And no one can agree how to indent it. *grin*</description>
		<content:encoded><![CDATA[<p>It makes sense, in a very stupid way, if you consider labeled statements /outside/ of a <code>switch</code>. You can&#8217;t label a declaration with a <code>goto</code>-style label because there&#8217;s no statement to <code>goto</code>.</p>
<p>But given the common use of switch statements, this is silly. Java (among other languages, maybe C++ too, I can&#8217;t remember) does the Right Thing by syntactically making declarations statements, and making sure the variables they&#8217;re declaring are usable in the rest of the block.</p>
<p>C&#8217;s <code>switch</code> is ugly anyways. And no one can agree how to indent it. *grin*</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case/comment-page-1#comment-243685</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Sat, 21 Feb 2009 02:09:39 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=929#comment-243685</guid>
		<description>My workaround is to put the case label on an empty statement:

&lt;pre&gt;case foo:;
	int foo_alpha;&lt;/pre&gt;

Looks ugly, but it works.</description>
		<content:encoded><![CDATA[<p>My workaround is to put the case label on an empty statement:</p>
<pre>case foo:;
	int foo_alpha;</pre>
<p>Looks ugly, but it works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ssp</title>
		<link>http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case/comment-page-1#comment-243683</link>
		<dc:creator>ssp</dc:creator>
		<pubDate>Sat, 21 Feb 2009 00:33:21 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=929#comment-243683</guid>
		<description>Your logic here may be impeccable – I couldn&#039;t take the pain of reading all the details, but I distinctly remember running into this dumbfuckery of C a few times and ending up either having defined my variables more globally than they need be or, in later iterations being amazed that the branch with some (coincidental) braces worked. 

So it&#039;s not a compiler bug, it&#039;s merely a C bug. Wonderful…</description>
		<content:encoded><![CDATA[<p>Your logic here may be impeccable – I couldn&#8217;t take the pain of reading all the details, but I distinctly remember running into this dumbfuckery of C a few times and ending up either having defined my variables more globally than they need be or, in later iterations being amazed that the branch with some (coincidental) braces worked. </p>
<p>So it&#8217;s not a compiler bug, it&#8217;s merely a C bug. Wonderful…</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Ash</title>
		<link>http://boredzo.org/blog/archives/2009-02-20/why-the-compiler-wont-let-you-declare-a-variable-immediately-after-a-case/comment-page-1#comment-243677</link>
		<dc:creator>Mike Ash</dc:creator>
		<pubDate>Fri, 20 Feb 2009 20:37:13 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=929#comment-243677</guid>
		<description>An extremely simple workaround is to just use braces with your case statements:

&lt;code&gt;
case foo:
{
&#160;&#160;&#160;&#160;int foo_alpha;
&#160;&#160;&#160;&#160;...
}
break;&lt;/code&gt;

Just be sure you don&#039;t forget the break at the end. The braces aren&#039;t enough for that!</description>
		<content:encoded><![CDATA[<p>An extremely simple workaround is to just use braces with your case statements:</p>
<p><code><br />
case foo:<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;int foo_alpha;<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}<br />
break;</code></p>
<p>Just be sure you don&#8217;t forget the break at the end. The braces aren&#8217;t enough for that!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.144 seconds -->

