<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>What about goto?</title>
		<link>http://www.allegro.cc/forums/view/590604</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 22 Mar 2007 04:39:25 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have a clouded memory of people saying &quot;goto shouldn&#39;t be used&quot;, but i can think of alot of places when i want to use it, so please tell me what you think||know about &quot;goto&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Albin Engström)</author>
		<pubDate>Sun, 18 Mar 2007 12:04:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://www.allegro.cc/forums/thread/589282">http://www.allegro.cc/forums/thread/589282</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 18 Mar 2007 12:20:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>goto <u>can</u> be very evil.</p><p>However it does have a few good uses. I can think of two right off the bat:
</p><ul><li><p>Error handling in large C functions. </p></li><li><p>Computed &quot;goto&quot; dispatch in a Virtual Machine&#39;s core.</p></li></ul><p>

edit: See the link in matthew&#39;s post <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 18 Mar 2007 12:21:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
so please tell me what you think||know about &quot;goto&quot;.
</p></div></div><p>

You don&#39;t need it, if you know how to use these instructions properly: do-while, switch, if-else.<br />Goto is ok for Basic programmers, but in C/C++ you have better and more elegant alternatives.<br />I have never used a goto in my C/C++ projects, and I will never do it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Sun, 18 Mar 2007 12:39:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Understood, thank you <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Albin Engström)</author>
		<pubDate>Sun, 18 Mar 2007 12:50:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Use goto when it makes your code clearer.  It&#39;s often used where you would use catch and finally blocks in java, ie. for jumping to some error cleanup code at the end of a function.  And sometimes it&#39;s the cleanest way of breaking out of nested loops.  But if you&#39;re using it to jump backwards, you better make sure there really isn&#39;t a better way.  I&#39;ve seen some messy code doing backwards jumps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 18 Mar 2007 19:30:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Goto is ok for Basic programmers, but in C/C++ you have better and more elegant alternatives.
</p></div></div><p>
Are there really versions of BASIC that don&#39;t have proper looping constructs? BBC BASIC has REPEAT...UNTIL, FOR...NEXT and IF...ELSE. (OK, come to think of it, it doesn&#39;t have multi-line IF. Hmm.) There&#39;s no SWITCH but you can do that using IFs (and C&#39;s &#39;switch&#39; is little more than gotos anyway, considering the way it falls through).</p><p>Incidentally, Java has a very good answer to &#39;goto&#39;. It lets you label any statement (including loop statements that contain lots of nested statements), and then any nested statement can be a &#39;break&#39; with that label - or a &#39;continue&#39; if the labelled statement is a loop. It means you can break out of arbitrarily nested loops and jump to the next statement afterwards, and it keeps your code well-structured. You do indeed end up with no way to jump back without using a loop.</p><p>In C and C++, I&#39;d have no problem with using a &#39;goto&#39; to simulate that.</p><p>I have also used &#39;goto&#39; to jump back though. I did that when the code wouldn&#39;t normally loop but there was just one specific case where I wanted it to repeat the body of the function. Sometimes it&#39;s a bit counter-intuitive to see a &#39;while&#39; loop when it&#39;s not obvious why the code is going to loop. It&#39;s arguable though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Sun, 18 Mar 2007 19:55:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>BP&#39;s right; the break and continue keywords are actually controlled goto&#39;s.</p><p>I think historically goto got a bad rap from back in the fortran/cobol days when that was all they had; Fortran didn&#39;t have if/then/else for a LONG time.  Cobols paragraph structure is a sort of controlled procedure branching construct that goto would desrupt. If you goto&#39;d/jumped out of a paragraph, the pgm would execute straight thru to the end. Then in the early MS basics like that on the c-64 all you had was goto and gosub.</p><p>In the 60&#39;s some guys proved that any flowchart could be implemented using only if/then/else and a pre-test loop like while(){}.   That&#39;s one thing that led to the &#39;structured programming&#39; revolution.  It&#39;s hard to believe that something we take for granted and seems so obvious was revolutionary at one time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Mon, 19 Mar 2007 00:56:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Then in the early MS basics like that on the c-64 all you had was goto and gosub.
</p></div></div><p><i>Lame!</i> The BBC Micro predated the C64, by about four years I believe.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Mon, 19 Mar 2007 01:08:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Goto is the way you handle exceptions in Visual Basic.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Mon, 19 Mar 2007 01:09:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Perl has some interesting semantics with labels and goto...</p><p>heres a nice quote from the man himself:
</p><div class="quote_container"><div class="title">Larry Wall said:</div><div class="quote"><p>
If I allowed &quot;next $label&quot; then I&#39;d also have to allow &quot;goto $label&quot;, and I don&#39;t think you really want that...  :-)
</p></div></div><p>

you can label a loop, and &quot;next/last&quot; on them, as if they were named loops. its rather handy.</p><div class="source-code snippet"><div class="inner"><pre>FOO:
<span class="k1">while</span><span class="k2">(</span>...<span class="k2">)</span> <span class="k2">{</span>
   BAR: <span class="k1">for</span><span class="k2">(</span>...<span class="k2">)</span> <span class="k2">{</span> ... next FOO <span class="k1">if</span> $blah<span class="k2">;</span> next BAR <span class="k1">if</span> $baz<span class="k2">;</span> ... <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 19 Mar 2007 01:28:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Goto is the buldozer of coding. Sometimes, the buldozer is just the right tool for the job. Not often, but sometimes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Mon, 19 Mar 2007 05:34:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Goto is the buldozer of coding. Sometimes, the buldozer is just the right tool for the job. Not often, but sometimes.
</p></div></div><p>Sigged for posterity.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 19 Mar 2007 07:23:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><i>&quot;Why does a dog lick its penis?&quot;</i><br /><i>&quot;Because it can.&quot;</i></p><p>I think goto is the most strange thing in C/C++. We all know it belongs to BASIC. We also know that it is a part of the standard C/C++. But I bet it is the only thing coders find strange, something that doesn&#39;t match the way of thinking and way of using the language.</p><p>I speak a kind of old Swedish (because I live in Finland), which is not influenced by English in same extent than the Swedish spoken in Sweden. It strikes me every time I see or hear a new English word in Swedish printed or spoken in Sweden, used as if it were a part of the language. But not only words. Some structures in sentences are also adapted from English. I find it horrible. A bit like using goto in C/C++.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Mon, 19 Mar 2007 08:30:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
But I bet it is the only thing coders find strange, something that doesn&#39;t match the way of thinking and way of using the language.
</p></div></div><p>
What about trigraphs?  And macros.  And the way &quot;&gt;&gt;&quot; is treated when terminating nested template parameters.  And the way variable initializations are sometimes treated as function declarations.  And...</p><p>Well, really, I agree with the point that goto is conceptually closer kin to asm or basic and is out of place in C and even farther from the intended paradigm of C++.  I&#39;m just saying that there&#39;s a bunch of other very strange stuff that somehow made it in to C++ too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Mon, 19 Mar 2007 11:27:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, you might be right, there are more oddities than goto. I never knew about trigraphs. I bet they go way back to the time when all computers used 7 bit ascii for everything. I have my Bondwell 16 in my attic (next to my Sinclair ZX81). It used 7 bit ascii and to be able to show scandinavian letters Å, Ä and Ö, it replaced [ \ ] with Ä Ö Å. On a very low system level. It was burnt into the 128k bios ROM.</p><p>I didn&#39;t code in C at that time, but I coded in Pascal. And instead of writing FooÄ16Å, I wrote Foo(. 16 .)</p><p>On a standard English/US machine that would be Foo[16]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Mon, 19 Mar 2007 17:09:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>Bad <span class="k3">=</span><span class="k3">=</span> <span class="k1">true</span><span class="k2">)</span>
         <span class="k1">goto</span> Hell<span class="k2">;</span>

Hell:
   Death <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
   Burn <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
   Pain <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Black)</author>
		<pubDate>Mon, 19 Mar 2007 18:45:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Possumdude0 said:</div><div class="quote"><p>
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>Bad <span class="k3">=</span><span class="k3">=</span> <span class="k1">true</span><span class="k2">)</span>
         <span class="k1">goto</span> Hell<span class="k2">;</span>

Hell:
   Death <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
   Burn <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
   Pain <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
</pre></div></div><p>
</p></div></div><p>
So we&#39;re all going to hell no matter what? <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dustin Dettmer)</author>
		<pubDate>Tue, 20 Mar 2007 02:38:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Of course!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Tue, 20 Mar 2007 02:46:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, only if <tt>Bad == true</tt>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rampage)</author>
		<pubDate>Tue, 20 Mar 2007 22:25:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But if Bad is not true, you fall back to the same place!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Tue, 20 Mar 2007 22:26:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oops, how could I miss that? I&#39;ll blame it on almost never using goto. Yes, that was it...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rampage)</author>
		<pubDate>Tue, 20 Mar 2007 22:39:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And the way &quot;&gt;&gt;&quot; is treated when terminating nested template parameters.
</p></div></div><p>Accepted in Java but not accepted in C++, I believe?</p><p>(Java also has to worry about &quot;&gt;&gt;&gt;&quot; <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />)
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And the way variable initializations are sometimes treated as function declarations.
</p></div></div><p>Eh? Got an example?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Wed, 21 Mar 2007 01:49:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And the way &quot;&gt;&gt;&quot; is treated when terminating nested template parameters.
</p></div></div><p>

This is fixed in C++0x, by the way.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Carrus85)</author>
		<pubDate>Wed, 21 Mar 2007 02:03:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
This is fixed in C++0x, by the way.
</p></div></div><p>
What&#39;s here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so &quot;&gt;&gt;&quot; will always be interpreted as bit shifting operator and not as two separate greater-than&#39;s. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Krzysztof Kluczek)</author>
		<pubDate>Wed, 21 Mar 2007 03:21:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In the Allegro source code, I think it&#39;s in the gui stuff, you&#39;ll find an army of goto&#39;s.  Suckers, you&#39;ve been using them without knowing all this time, Mwa-ha-ha-ha-ha! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matt Weir)</author>
		<pubDate>Wed, 21 Mar 2007 03:37:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What&#39;s here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so &quot;&gt;&gt;&quot; will always be interpreted as bit shifting operator and not as two separate greater-than&#39;s. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div></div><p>

And templates within templates?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rampage)</author>
		<pubDate>Wed, 21 Mar 2007 03:55:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And templates within templates?
</p></div></div><p>
Template arguments are specified using &lt; an &gt; operators, so its reasonable that &lt; and &gt;&gt; operators shouldn&#39;t work here. I&#39;m not sure how they are going to &quot;fix&quot; this in C++0x as this will overcomplicate either parser or syntax analyzer. In first case parser will have to know whether &gt;&gt; should be passed to syntax analyzer as &gt;&gt; operator or two &gt;&#39;s. In second case syntax analyzer will have to be aware of starting &lt; which could have been many lines earlier. In C++ as it is now syntax analyzer has only to look one symbol forward, which makes writing C++ parser using bison/yacc quite straightforward. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Krzysztof Kluczek)</author>
		<pubDate>Wed, 21 Mar 2007 04:15:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What&#39;s here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so &quot;&gt;&gt;&quot; will always be interpreted as bit shifting operator and not as two separate greater-than&#39;s. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div></div><p>Which is stupid. Theres context there to know what you&#39;ve been parsing. You just saw a template started, why not realize that and see that its two separate &gt;&#39;s? Most parsers, especially generated ones, are too damn stupid to be of any real use. Just look at the horrible error messages they put out. They just don&#39;t have enough context to realize that the actual error is/was.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
this will overcomplicate either parser or syntax analyzer.
</p></div></div><p>Hardly. GCC 4 has already replaced their DUMB bison/yacc parsers with hand rolled recursive decent parsers, which are already faster, but should allow error messages to improve (since you can place them at any point, instead of at places a generated parser finally notices an error), and allow the parser to know what its parsing. Its not that hard.</p><p>I have an oldish project that uses a lexicalanalyzer setup that allows you to push and pop modes for parsing, like for example, when parsing HTML, you can pop on a CSS analyzer, or javascript, all while the same parser pass is executing. Something like that, just done a little better would fix all the issues.</p><p>The <u>only</u> time complicating the parser/scanner in a compiler mattered was when you only had 2K ram <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> Who bloody cares that theres a few extra KB of code in the compiler when it can <u>properly</u> parse, parses faster, and provides MUCH better error reports?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 21 Mar 2007 04:26:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Which is stupid. Theres context there to know what you&#39;ve been parsing. You just saw a template started, why not realize that and see that its two separate &gt;&#39;s?
</p></div></div><p>
Then parse the code below. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">template</span><span class="k3">&lt;</span><span class="k1">class</span> _T&gt; <span class="k1">class</span> foo<span class="k2">;</span>
<span class="k1">template</span><span class="k3">&lt;</span><span class="k1">int</span> _I&gt; <span class="k1">class</span> bar<span class="k2">;</span>

foo<span class="k3">&lt;</span> bar<span class="k3">&lt;</span> <span class="n">1024</span> <span class="k3">&gt;</span><span class="k3">&gt;</span> <span class="n">2</span> <span class="k3">&gt;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Krzysztof Kluczek)</author>
		<pubDate>Wed, 21 Mar 2007 04:32:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><tt>2</tt> isn&#39;t a valid symbol name, so you obviously meant<br /><span class="source-code">foo<span class="k3">&lt;</span> bar<span class="k3">&lt;</span> <span class="k2">(</span><span class="n">1024</span> <span class="k3">&gt;</span><span class="k3">&gt;</span> <span class="n">2</span><span class="k2">)</span> <span class="k3">&gt;</span></span><br />and there&#39;s no harm in requiring the parenthesis, IMO. Also, you&#39;re missing a &gt;. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 21 Mar 2007 04:50:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What&#39;s here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so &quot;&gt;&gt;&quot; will always be interpreted as bit shifting operator and not as two separate greater-than&#39;s. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div></div><p>

&lt; and &gt; are also used as matched pairs in template parameter lists.  And, when multiple nested templates argument lists are terminated without anything intervening, the syntax gets rather weird.   For an example with three levels of nesting, these are equivalent ways of naming the same type:
</p><div class="source-code snippet"><div class="inner"><pre>std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span><span class="k1">int</span> <span class="k3">&gt;</span> <span class="k3">&gt;</span> <span class="k3">&gt;</span>
std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span>int&gt;&gt;&gt;&gt;&gt;&gt;
std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span>int&gt;&gt;&gt;&gt;&gt;
</pre></div></div><p>

</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And the way variable initializations are sometimes treated as function declarations.
</p></div></div><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Eh? Got an example?
</p></div></div><p>
Hm... I thought this was covered in Myers Effective C++, but I can&#39;t find it right now.  <br />Well, some quick experimentation turns up a case where things look a bit odd... this isn&#39;t much but it&#39;s the closest I can come up with atm:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> Foo <span class="k2">{</span>
public:
  <span class="k1">int</span> a<span class="k2">;</span>
  Foo <span class="k2">(</span> <span class="k2">)</span> <span class="k2">:</span> a<span class="k2">(</span><span class="n">0</span><span class="k2">)</span> <span class="k2">{</span><span class="k2">}</span>
<span class="k2">}</span><span class="k2">;</span>
<span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span> <span class="k2">{</span>
  Foo bob<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%d\n"</span>, bob.a<span class="k2">)</span><span class="k2">;</span><span class="c">//compile error; bob is a function, not an object</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Wed, 21 Mar 2007 05:06:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
For an example with three levels of nesting, these are equivalent ways of naming the same type:
</p></div></div><p>
That implies that someone decided &quot;&gt;&gt;&quot; should be accepted as a substitute for a single &quot;&gt;&quot; in that context. Surely that&#39;s going to be even more confusing than just saying &quot;Unexpected token &#39;&gt;&gt;&#39;&quot;?</p><p>I can see what you mean about the functions and variables now. Wow, C++ is such a mess <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /> Thanks for the example <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Wed, 21 Mar 2007 05:11:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I concede, C++ is so crappily designed that even a proper statefull parser couldn&#39;t easily handle it. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 21 Mar 2007 05:29:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">orz said:</div><div class="quote"><p>
&lt; and &gt; are also used as matched pairs in template parameter lists. And, when multiple nested templates argument lists are terminated without anything intervening, the syntax gets rather weird. For an example with three levels of nesting, these are equivalent ways of naming the same type:<br />std::vector&lt;std::pair&lt;int,std::list&lt;int &gt; &gt; &gt;<br />std::vector&lt;std::pair&lt;int,std::list&lt;int&gt;&gt;&gt;&gt;&gt;&gt;<br />std::vector&lt;std::pair&lt;int,std::list&lt;int&gt;&gt;&gt;&gt;&gt;
</p></div></div><p>

Umm...</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;vector&gt;</span>
<span class="p">#include &lt;list&gt;</span>
<span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
  std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span><span class="k1">int</span> <span class="k3">&gt;</span> <span class="k3">&gt;</span> <span class="k3">&gt;</span> foo1<span class="k2">;</span>
  std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span>int&gt;&gt;&gt;&gt;&gt;&gt; foo2<span class="k2">;</span>
  std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span>int&gt;&gt;&gt;&gt;&gt;  foo3<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

MSVC 7.1:
</p><pre>
$ cl temp.cpp -nologo
temp.cpp
temp.cpp(5) : error C2947: expecting &#39;&gt;&#39; to terminate template-argument-list, found &#39;&gt;&gt;&#39;
temp.cpp(5) : error C2947: expecting &#39;&gt;&#39; to terminate template-argument-list, found &#39;&gt;&gt;&#39;
temp.cpp(5) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
temp.cpp(5) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
temp.cpp(6) : error C2947: expecting &#39;&gt;&#39; to terminate template-argument-list, found &#39;&gt;&gt;&#39;
temp.cpp(6) : error C2947: expecting &#39;&gt;&#39; to terminate template-argument-list, found &#39;&gt;&gt;&#39;
temp.cpp(6) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
temp.cpp(6) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
</pre><p>

MSVC 8.0:
</p><pre>
$ cl -nologo temp.cpp
temp.cpp
temp.cpp(5) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
temp.cpp(5) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
temp.cpp(6) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
temp.cpp(6) : error C2143: syntax error : missing &#39;;&#39; before &#39;&gt;&#39;
</pre><p>

GCC 3.4.4:
</p><pre>
$ gcc temp.cpp
temp.cpp: In function `int main()&#39;:
temp.cpp:5: error: `&gt;&gt;&#39; should be `&gt; &gt;&#39; within a nested template argument list
temp.cpp:5: error: `foo2&#39; undeclared (first use this function)
temp.cpp:5: error: (Each undeclared identifier is reported only once for each function it appears in.)
temp.cpp:5: error: spurious `&gt;&gt;&#39;, use `&gt;&#39; to terminate a template argument list
temp.cpp:5: error: expected primary-expression before &#39;&gt;&gt;&#39; token
temp.cpp:6: error: `&gt;&gt;&#39; should be `&gt; &gt;&#39; within a nested template argument list
temp.cpp:6: error: spurious `&gt;&gt;&#39;, use `&gt;&#39; to terminate a template argument list
temp.cpp:6: error: expected primary-expression before &#39;&gt;&#39; token
temp.cpp:6: error: `foo3&#39; undeclared (first use this function)
</pre><p>

The C++ standard has no mention of this in the template grammar.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Wed, 21 Mar 2007 07:05:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hm... perhaps that was MSVC6 only?  Certainly I wouldn&#39;t actually choose that syntax, but I have seen it work.  <br />edit: anyway, the most important point is that <br /><span class="source-code">std::vector<span class="k3">&lt;</span>std::pair<span class="k3">&lt;</span><span class="k1">int</span>,std::list<span class="k3">&lt;</span>int&gt;&gt;&gt; foo1<span class="k2">;</span></span><br />is not valid
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Wed, 21 Mar 2007 07:45:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Then parse the code below. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div></div><p>Here you are <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;iostream&gt;</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="k1">template</span><span class="k3">&lt;</span><span class="k1">class</span> _T&gt; <span class="k1">class</span> foo<span class="k2">{</span></td></tr><tr><td class="number">4</td><td>  _T k<span class="k2">;</span></td></tr><tr><td class="number">5</td><td><span class="k2">}</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td><span class="k1">template</span><span class="k3">&lt;</span><span class="k1">int</span> _I&gt; <span class="k1">class</span> bar<span class="k2">{</span></td></tr><tr><td class="number">7</td><td>  <span class="k1">int</span> i<span class="k2">;</span></td></tr><tr><td class="number">8</td><td>  public:</td></tr><tr><td class="number">9</td><td>  bar<span class="k2">(</span><span class="k2">)</span><span class="k2">:</span> i<span class="k2">(</span>_I<span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">10</td><td>    std::cout<span class="k3">&lt;</span><span class="k3">&lt;</span>i<span class="k3">&lt;</span><span class="k3">&lt;</span>std::endl<span class="k2">;</span></td></tr><tr><td class="number">11</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td><span class="k2">}</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">16</td><td>  foo<span class="k3">&lt;</span> bar<span class="k3">&lt;</span> <span class="n">1024</span> <span class="k3">&gt;</span><span class="k3">&gt;</span> <span class="n">2</span> <span class="k3">&gt;</span> <span class="k3">&gt;</span> a<span class="k2">;</span></td></tr><tr><td class="number">17</td><td>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>compiled without any warnings and printed out 256 <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><br />gcc version 4.1.2 (Gentoo 4.1.2)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Wed, 21 Mar 2007 14:09:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Quote:<br />Then parse the code below. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Here you are <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div></div><p>
Yes, I know that it should work OK. The question arises when we allow &gt;&gt; to be interpreted as two &gt;&#39;s closing two templates - the compiler comes to &gt;&gt; and isn&#39;t quite sure whether to treat it as two &gt;&#39;s or one &gt;&gt;. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Krzysztof Kluczek)</author>
		<pubDate>Wed, 21 Mar 2007 14:26:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Technically, if it has access to the symboltable as it parses, and has some extra lookahead, it can see its in foo and bar, and needs a int, which 1024 &gt;&gt; 2 resolves to. Its not impossible, and I bet at somepoint GCC could handle it with its new parser, unless they decide to stick strictly to the specs, which it never has before (gcc has the best extensions <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 21 Mar 2007 22:25:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wow, lot&#39;s of interesting issues I never thought about, and probably never will... Anyway, what are trigraphs? And how would you label loops in Java? I don&#39;t recall ever seeing such a thing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ron Ofir)</author>
		<pubDate>Wed, 21 Mar 2007 23:45:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Yes, I know that it should work OK. The question arises when we allow &gt;&gt; to be interpreted as two &gt;&#39;s closing two templates - the compiler comes to &gt;&gt; and isn&#39;t quite sure whether to treat it as two &gt;&#39;s or one &gt;&gt;. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div></div><p>

Ick. If that&#39;s C++0x, I&#39;m sticking to C++ &amp;&amp; Boost.</p><p>Same neat features, none of the insanity.</p><p>Edit: <a href="http://en.wikipedia.org/wiki/C_trigraph">Trigraphs.</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Thu, 22 Mar 2007 00:40:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>C++ is over. C# by far is superior.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Thu, 22 Mar 2007 04:39:25 +0000</pubDate>
	</item>
</rss>

