<?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>/dev/mobile &#187; Random Notes</title>
	<atom:link href="http://www.christec.co.nz/blog/archives/category/random-notes/feed" rel="self" type="application/rss+xml" />
	<link>http://www.christec.co.nz</link>
	<description>Development for a mobile world - Making a quality platform one application at a time</description>
	<lastBuildDate>Tue, 27 Oct 2009 09:56:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Will the following C# compile?</title>
		<link>http://www.christec.co.nz/blog/archives/140</link>
		<comments>http://www.christec.co.nz/blog/archives/140#comments</comments>
		<pubDate>Wed, 03 Oct 2007 10:49:34 +0000</pubDate>
		<dc:creator>Christopher Fairbairn</dc:creator>
				<category><![CDATA[Random Notes]]></category>

		<guid isPermaLink="false">http://www.christec.co.nz/blog/archives/140</guid>
		<description><![CDATA[While reviewing some code earlier his week, I came across a C# function which when reduced to its core essentials boiled down to the following sample:
public void SomeMethod()
{
     http://www.christec.co.nz  

     MessageBox.Show("hello world");
}
Off the top of your head do you think a C# compiler would happily accept [...]]]></description>
			<content:encoded><![CDATA[<p>While reviewing some code earlier his week, I came across a C# function which when reduced to its core essentials boiled down to the following sample:</p>
<pre>public void SomeMethod()
{
     http://www.christec.co.nz  

     MessageBox.Show("hello world");
}</pre>
<p>Off the top of your head do you think a C# compiler would happily accept this source code, or would you expect a syntax error?</p>
<p>The answer is that the above example function is completely valid C# source code. It is easier to see why once syntax highlighting has been applied to it.</p>
<p>The // characters after the http: prefix cause the rest of the URL to be interpreted as a comment, and the bit which is left (http:) is in the correct syntax to be interpreted as a label for use with the <a href="http://msdn2.microsoft.com/en-us/library/13940fs2(VS.80).aspx">goto statement</a>.</p>
<p>I had accidentally pasted a URL into my source code and checked it into our source control system. I didn&#8217;t notice for a few weeks since the code compiled and executed perfectly&#8230;</p>
<p>An amusing (but somewhat useless) application of this fact can be found in the following program</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MyDumbApplication
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span> 
     http<span style="color: #008000;">:</span><span style="color: #008080; font-style: italic;">//www.christec.co.nz  </span>
&nbsp;
     Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Hello World!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  
&nbsp;
     <span style="color: #0600FF;">goto</span> http<span style="color: #008000;">;</span> 
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I wonder if this fact could be used to advantage in a <a href="http://en.wikipedia.org/wiki/International_Obfuscated_C_Code_Contest">International Obfuscated C Code Contest</a> style C# program?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christec.co.nz/blog/archives/140/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
