<?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>James&#039;s Blog</title>
	<atom:link href="http://www.hempnall.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.hempnall.com/blog</link>
	<description>Just a few notes about working in an computing driven world. I&#039;ve even been known to refer back to them from time to time.</description>
	<lastBuildDate>Sat, 24 Dec 2011 10:59:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Differences between C# and Java</title>
		<link>http://www.hempnall.com/blog/?p=50</link>
		<comments>http://www.hempnall.com/blog/?p=50#comments</comments>
		<pubDate>Sat, 24 Dec 2011 10:59:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com/blog/?p=50</guid>
		<description><![CDATA[I&#8217;ve just had convert some C# into Java and have noticed the following differences between these two languages (that are often thought to be so similar as to make no difference). In no particular order: Java uses packages, C# uses &#8230; <a href="http://www.hempnall.com/blog/?p=50">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just had convert some C# into Java and have noticed the following differences between these two languages (that are often thought to be so similar as to make no difference). In no particular order:
</p>
<ul>
<li>Java uses packages, C# uses namespaces
</li>
<li>Java uses &#8220;import&#8221; to bring in classes, C# uses &#8220;using&#8221;
</li>
<li>Java classes (public ones) must be in a .java file with the same name as the class, C# doesn&#8217;t care
</li>
<li>Java Strings must be Strings, C# has strings as well
</li>
<li>Java doesn&#8217;t have &#8216;out&#8217; parameters
</li>
<li>Java functions must declare if they throw exceptions, C# doesn&#8217;t care
</li>
<li>Java doesn&#8217;t have unsigned integer types, C# does
</li>
<li>Java system namespaces start with &#8220;java.*&#8221;, C#&#8217;s start with &#8220;System.*&#8221;
</li>
<li>Java doesn&#8217;t have support for accessor/setter methods in the language, C# does
</li>
<li>Java uses words like &#8220;implements&#8221; and &#8220;extends&#8221; for inheritance, C# uses the : operator
</li>
<li>Java doesn&#8217;t have a .TryParse method, C# does
</li>
<li>Java has final, C# has const and readonly
</li>
<li>Java can&#8217;t use enum constants in switch statements, C# can
</li>
<li>
<div>Java can&#8217;t use [] on a String to access chars, C# can.
</div>
<p>
 </p>
</li>
</ul>
<p>Not a problem for the current exercise, but other differences are:
</p>
<ul>
<li>Java misses partial classes
</li>
<li>Java misses lamda functions (although there are proposals to include Lamda functions in Java BGGA)
</li>
<li>Java (out of the box) doesn&#8217;t have some of the functional features of C#
</li>
</ul>
<p>There are only a couple of things I would conclude from this
</p>
<ul>
<li>Don&#8217;t assume that C# is a superior language just because it has loads more <span style="text-decoration:line-through">bling </span>features
</li>
<li>Don&#8217;t underestimate the task of converting non-trivial C# classes to Java</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=50</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breaking the Java Compiler with ANTLR</title>
		<link>http://www.hempnall.com/blog/?p=49</link>
		<comments>http://www.hempnall.com/blog/?p=49#comments</comments>
		<pubDate>Sun, 02 Oct 2011 13:40:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=49</guid>
		<description><![CDATA[I&#8217;ve been doing a bit of work with ANTLR and Java. The work was gathering momentum and I had developed a modest size set of ANTLR rules from which I was generating Java code. To be honest, I was feeling &#8230; <a href="http://www.hempnall.com/blog/?p=49">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a bit of work with ANTLR and Java. The work was gathering momentum and I had developed a modest size set of ANTLR rules from which I was generating Java code. To be honest, I was feeling quite good about life at this point.</p>
<p>Then from out of nowhere came a Java compiler error…</p>
<p>[along the lines of] Java method size exceeds 64 KB.</p>
<p>Now I thought limits like this were banished from the world of computing well before the days of Java. But no, the Java class file formats stores method lengths in 2 bytes, and it would appear this is a showstopper.</p>
<p>Fortunately, ANTLR is clever enough to reduce the size of its code generated methods. Instead of many nested &#8220;if&#8221; statements, it can use a table of DFA states. To achieve this, you must use the following command line to generate the Java code (I couldn&#8217;t find a way to do this ANTLRWORKS)</p>
<p><span style="font-family: Courier New;">C: java org.antlr.Tool –Xmaxinlinedfastates [a number less than 60] grammar.g<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=49</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kamikaze?</title>
		<link>http://www.hempnall.com/blog/?p=47</link>
		<comments>http://www.hempnall.com/blog/?p=47#comments</comments>
		<pubDate>Fri, 16 Sep 2011 08:48:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=47</guid>
		<description><![CDATA[Why do so many developers feel the need to model themselves around Japenese warriors of old? (I&#8217;ve seen quite a few Samurais out there on the Internet).]]></description>
			<content:encoded><![CDATA[<p>Why do so many developers feel the need to model themselves around Japenese warriors of old? (I&#8217;ve seen quite a few Samurais out there on the Internet).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Social Responsibility for Geeks – Chapter One</title>
		<link>http://www.hempnall.com/blog/?p=44</link>
		<comments>http://www.hempnall.com/blog/?p=44#comments</comments>
		<pubDate>Sun, 12 Jun 2011 08:25:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=44</guid>
		<description><![CDATA[Well, I attended a developer event yesterday and you won&#8217;t be surprised to hear that several people describe their projects and technology as &#8220;awesome&#8221;. I think this word is overused. Something is only awesome if it contributes (in a significant &#8230; <a href="http://www.hempnall.com/blog/?p=44">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Well, I attended a developer event yesterday and you won&#8217;t be surprised to hear that several people describe their projects and technology as &#8220;awesome&#8221;. I think this word is overused.
</p>
<p>Something is only awesome if it contributes (in a significant and transparent way) to:
</p>
<ul>
<li>The end of disease
</li>
<li>World peace
</li>
<li>The end of prejudice and injustice
</li>
<li>….
</li>
</ul>
<p>Otherwise, please refrain from exaggerating, and stick with being mildly pleased with whatever you have achieved, and think about whether you have actually contributed to any of the above goals!
</p>
<p>
 </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=44</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Higher Order Functions</title>
		<link>http://www.hempnall.com/blog/?p=24</link>
		<comments>http://www.hempnall.com/blog/?p=24#comments</comments>
		<pubDate>Sun, 20 Mar 2011 13:33:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=24</guid>
		<description><![CDATA[I&#8217;ve been doing a bit C#,F# and C++ recently and have started to use higher order functions a lot. I think they are a great way of simplifying code, so you&#8217;ll spending more time writing domain specific code rather than &#8230; <a href="http://www.hempnall.com/blog/?p=24">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Georgia; font-size: 12pt;">I&#8217;ve been doing a bit C#,F# and C++ recently and have started to use higher order functions a lot. I think they are a great way of simplifying code, so you&#8217;ll spending more time writing domain specific code rather than having to keep writing while and for loops, and having to keep balancing brackets.<br />
</span>    </p>
<p><span style="font-family: Georgia; font-size: 12pt;">Why should you use higher order functions? Well, one reason is that your code can be optimised without having to make any large changes. For instance, the parallel version of some of the higher order functions has virtually identical syntax to the single threaded version.<br />
</span>    </p>
<p><span style="font-family: Georgia; font-size: 12pt;">One of the confusing things about the higher order functions is that they have different names across the different languages. This shouldn&#8217;t matter too much, but I&#8217;m still seeing the need to do a comparison across the three languages (stated above) just to get it clear in my head.<br />
</span>    </p>
<p><span style="font-family: Georgia; font-size: 12pt;">So, here goes&#8230;<br />
</span></p>
<table style="border-collapse: collapse;" border="0">
<colgroup span="1">
<col style="width: 184px;" span="1"></col>
<col style="width: 156px;" span="1"></col>
<col style="width: 618px;" span="1"></col>
</colgroup>
<tbody>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border: solid 0.5pt;" rowspan="3"><span style="font-family: Georgia; font-size: 12pt;">Set Iteration</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: solid 0.5pt; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">F#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: solid 0.5pt; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> <br />
<code>let myArray = [| 1 ; 2 ; 3 |]<br />
myArray |&gt; Seq.iter (fun x -&gt; printfn "%d" (x * 2)) </code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> <br />
<code>int[] myArray = new int[] { 1, 2, 3 };<br />
Array.ForEach(<br />
myArray,<br />
(i) =&gt; System.Console.WriteLine(i*2)<br />
);</code>  </td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C++ STL</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> <br />
<code>int arrayVals[] = {1,2,3};<br />
std::vector&lt;int&gt;myArray(arrayVals,&amp;arrayVals[3]);<br />
std::for_each (<br />
myArray.begin(),<br />
myArray.end(),<br />
[&amp;](int n){<br />
std::cout &lt;&lt; (n*2) &lt;&lt; std::endl;<br />
}<br />
);</code>  </td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;" rowspan="3">Set mapping</td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">F#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> <br />
<code>let myArrayDoubled = myArray |&gt; Seq.map (fun x -&gt; x*2)</code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;">  </p>
<div><code>int[] doubledSet = myArray.Select( (n) =&gt; n*2 </code></div>
<p>  </p>
<div><code>).ToArray(); </code></div>
<p> </p>
<p><code>  </p>
<p></code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C++ STL</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;">
<div><code>int doublen(int n){ </code></div>
<p>  </p>
<div><code>return n*2; </code></div>
<p> </p>
<p><code>}  </p>
<p>…  </p>
<p>std::vector&lt;int&gt; doubledArray;  </p>
<p>std::transform(  </p>
<p>myArray.begin(),  </p>
<p>myArray.end(),  </p>
<p>std::back_inserter(doubledArray),  </p>
<p>&amp;doublen  </p>
<p>);  </p>
<p></code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;" rowspan="3">Set concatenation</td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">F#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;">  </p>
<div><code>let myListOfArrays = [ [| 1;2;3 |] ; </code></div>
<p>  </p>
<div><code>[| 4;5;6 |] ; </code></div>
<p> </p>
<p><code>[| 7;8;9 |] ]  </p>
<p>let concatenatedList = Seq.concat myListOfArrays  </p>
<p></code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;">  </p>
<div><code>List&lt;int[]&gt; myListOfArrays = new List&lt;int[]&gt;(); </code></div>
<p>  </p>
<div><code>myListOfArrays.Add( </code></div>
<p> </p>
<p><code>new int[] { 1, 2, 3 });  </p>
<p>myListOfArrays.Add(  </p>
<p>new int[] { 4, 5, 6 });  </p>
<p>myListOfArrays.Add(  </p>
<p>new int[] { 7, 8, 9 });  </p>
<p>int[] newArray = myListOfArrays.SelectMany(  </p>
<p>(n) =&gt; n).ToArray();  </p>
<p></code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C++ STL</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> I think you could do something here with “accumulate” and a functor object – but as far as I can see there is nothing “out of the box” to do this.</td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;" rowspan="3">Fold (aggregation)</td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">F#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;">  </p>
<div><code>let total = myArray |&gt; </code></div>
<p>  </p>
<div><code>Seq.fold ( </code></div>
<p> </p>
<p><code>fun state item -&gt; state + item)  </p>
<p>0 // initial value of state  </p>
<p>printfn "%d" total    </p>
<p></code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><code>int total = myArray.Aggregate(0, (state, item) =&gt; state + item);</code></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C++ STL</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> int total =   std::accumulate(       myArray.begin(),    </p>
<p>       myArray.end(),    </p>
<p>       0    </p>
<p>);    </td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;" rowspan="3">Unfold (set initialisation)</td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">F#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> <span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"> <span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;">let <span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;">fibs = (1,1) |&gt; Seq.unfold (</span></span><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;">fun</span></span></span><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"> (n0,n1) </span></span><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;">-&gt;</span></span></span><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"> Some(n0,(n1,n0 + n1)))</span></span> </span></span></span></span></span></span></span></span></span></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C#</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> static IEnumerable&lt;int&gt; Fibonacci(int n0, int n1)<br />
{<br />
 int _n0 = n0;<br />
        int _n1 = n1;<br />
        yield return n0;<br />
        yield return n1;<br />
        while (true)<br />
        {<br />
            int temp = _n1;<br />
            _n1 = _n0 + _n1;<br />
            _n0 = temp;<br />
            yield return _n1;<br />
        }<br />
} &#8230; </p>
<div><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;">var</span></span></span><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"> fib = Fibonacci(1, 1);</span></span> </span></span></div>
<div><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;"><span style="font-family: Courier New; color: #0000ff; font-size: x-small;">int</span></span></span><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;">[] first5fib = fib.Take(5).ToArray();</span></span> </span></span></div>
<p>  </p>
<div><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;">  </span></span></div>
<p> </p>
<p><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;">  </p>
<p></span></span></td>
</tr>
<tr>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"><span style="font-family: Georgia; font-size: 12pt;">C++ STL</span></td>
<td style="padding-left: 11px; padding-right: 11px; border-top: none; border-left: none; border-bottom: solid 0.5pt; border-right: solid 0.5pt;"> std::vector&lt;int&gt; fibseq;<br />
Fibonacci acc(1,1);<br />
std::generate_n(<br />
 back_inserter(fibseq),<br />
 5,<br />
 acc<br />
); &#8230; class Fibonacci<br />
{<br />
 int _x0;<br />
 int _x1;<br />
 int _callcount;  public:<br />
 Fibonacci(int x0,int x1)<br />
  : _x0(x0),<br />
   _x1(x1),<br />
   _callcount(0)<br />
 {<br />
 }   </p>
<p> int operator() ()<br />
 {<br />
  if (_callcount == 0)<br />
  {<br />
   ++_callcount;<br />
   return _x0;<br />
  }<br />
  else if (_callcount++ == 1)<br />
  {<br />
   ++_callcount;<br />
   return _x1;<br />
  }<br />
  else<br />
  {<br />
   int temp = _x1;<br />
   _x1 = _x0 + _x1;<br />
   _x0 = temp;<br />
   return _x1;<br />
  }<br />
 }<br />
};   </td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=24</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The trials of porting Visual C++ projects to gcc on Linux</title>
		<link>http://www.hempnall.com/blog/?p=9</link>
		<comments>http://www.hempnall.com/blog/?p=9#comments</comments>
		<pubDate>Tue, 25 Jan 2011 09:19:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=9</guid>
		<description><![CDATA[Recently I have had the pleasurable experience of porting some C++ code developed on Visual Studio 2010 to work on GCC on Linux. You&#8217;d have thought with C++ being a defined standard it would just work (but then you stop &#8230; <a href="http://www.hempnall.com/blog/?p=9">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I have had the pleasurable experience of porting some C++ code developed on Visual Studio 2010 to work on GCC on Linux. You&#8217;d have thought with C++ being a defined standard it would just work (but then you stop dreaming). Here is a list of the problems I encountered:</p>
<ul>
<li><strong>#includes are case sensitive</strong></li>
</ul>
<p><code>#include "stdio.h"</code> does not equal <code>#include "Stdio.h"</code><br />
This was easy to fix.</p>
<ul>
<li>dependant types must be prefixed with the &#8220;typename&#8221; keyword</li>
</ul>
<p>I had a templated class, in which I was using one of the STL&#8217;s template containers with the template class. An example explains this better&#8230;<br />
<code><br />
// in Visual C++<br />
template&lt;class T&gt;<br />
class MyClass&lt;T&gt;<br />
{<br />
...<br />
void MyMethod()<br />
{<br />
...<br />
std::vector&lt;T&gt;::iterator it;<br />
...<br />
}<br />
...<br />
};<br />
</code><br />
GCC requires <code>std::vector::iterator</code> to be prefixed with the typename keyword. At least GCC compiler errors pointed me in the right direction.</p>
<ul>
<li>compiler warnings in Visual C++ are compiler errors on GCC</li>
</ul>
<p> GCC is much more fussy about the types you are allowed to implicitly cast between. Putting a few explicit casts into the code fixed this one.</p>
<ul>
<li>default boolean return type is false on GCC, true on Visual C++</li>
</ul>
<p>This was an odd one. I had a method with a boolean return type. Except I wasn&#8217;t returning anything..<br />
<code><br />
bool method()<br />
{<br />
// no return statement<br />
}<br />
...<br />
bMethodSuccess = method();<br />
...<br />
</code><br />
I would have thought that this shouldn&#8217;t compile &#8211; yet it did, and Visual C++ was not setting bMethodSuccess. However, Gcc will generate the code to return false, resulting in a program that behaves differently. Slapped wrist for not spotting this sooner.</p>
<p>I expect I might find other subtleties, so I may update this blog post in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=9</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just a quick try out</title>
		<link>http://www.hempnall.com/blog/?p=5</link>
		<comments>http://www.hempnall.com/blog/?p=5#comments</comments>
		<pubDate>Sun, 31 Oct 2010 18:11:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=5</guid>
		<description><![CDATA[You can type a bit in here blah blah for (int i=1;i]]></description>
			<content:encoded><![CDATA[<p>You can type a bit in here</p>
<blockquote><p>blah blah</p></blockquote>
<p><code>for (int i=1;i<4;i++) j++;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=5</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://www.hempnall.com/blog/?p=42</link>
		<comments>http://www.hempnall.com/blog/?p=42#comments</comments>
		<pubDate>Tue, 06 Jul 2010 10:23:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com:/blog/?p=1</guid>
		<description><![CDATA[Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!]]></description>
			<content:encoded><![CDATA[<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=42</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://www.hempnall.com/blog/?p=1</link>
		<comments>http://www.hempnall.com/blog/?p=1#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hempnall.com/blog/?p=1</guid>
		<description><![CDATA[Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!]]></description>
			<content:encoded><![CDATA[<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hempnall.com/blog/?feed=rss2&#038;p=1</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

