<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://www.liamdevine.co.uk/blog/wp-atom.php">
	<title type="text">LiamDevine.co.uk :: Blog</title>
	<subtitle type="text" />

	<updated>2010-01-01T12:00:41Z</updated>
	<generator uri="http://wordpress.org/" version="2.7.1">WordPress</generator>

	<link rel="alternate" type="text/html" href="http://www.liamdevine.co.uk/blog" />
	<id>http://www.liamdevine.co.uk/blog/feed/atom/</id>
	

			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/LiamdevinecoukBlog" /><feedburner:info uri="liamdevinecoukblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>LiamdevinecoukBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[The strangest of switch statements]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/by9DwfJQxXQ/" />
		<id>http://www.liamdevine.co.uk/blog/?p=129</id>
		<updated>2010-01-01T12:00:41Z</updated>
		<published>2010-01-01T11:57:18Z</published>
				<summary type="html"><![CDATA[When compiled as C this is a perfectly valid piece of code, yet you would have to be a few sandwiches short of a pick nick basket to write it (or an evil genius).

#include &#34;stdio.h&#34;
int is_even(unsigned char c)
{
        return c &#38; 0x01 ? 0: 1;
}

int main()
{
   [...]]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2010/01/the-strangest-of-switch-statements/"><![CDATA[<p>When compiled as C this is a perfectly <a href="http://www.bezem.de/2009/11/bizarre-switch-statement-in-c/">valid</a> piece of code, yet you would have to be a few sandwiches short of a pick nick basket to write it (or an evil genius).</p>
<pre class="brush: cpp;">
#include &quot;stdio.h&quot;
int is_even(unsigned char c)
{
        return c &amp; 0x01 ? 0: 1;
}

int main()
{
        unsigned char c =4;
        switch(c)
        {
                default:
                        if(is_even(c))
                case 2: case 4: case 6: case 8: case 10:
                                printf(&quot;is even\n&quot;);
                        else
                case 1: case 3: case 5: case 7: case 9:
                                printf(&quot;is not even\n&quot;);
        }
        return 0;
}
</pre>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2010/01/the-strangest-of-switch-statements/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2010/01/the-strangest-of-switch-statements/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2010/01/the-strangest-of-switch-statements/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[String Calculator Kata]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/cNlF1_tsTjg/" />
		<id>http://www.liamdevine.co.uk/blog/?p=103</id>
		<updated>2009-12-30T20:13:06Z</updated>
		<published>2009-12-30T14:50:27Z</published>
				<summary type="html"><![CDATA[Roy Osherove&#8217;s string calculator kata has been implemented in a number of languages, after trying it a couple of days ago and liking it I created a screen cast of my attempt. Incidentally if you want to view it is maybe best to view in high definition on vimeo.
I have added a download which includes [...]]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2009/12/string-calculator-kata/"><![CDATA[<p>Roy Osherove&#8217;s string calculator <a href="http://osherove.com/tdd-kata-1/">kata</a> has been implemented in a number of languages, after trying it a couple of days ago and liking it I created a screen cast of my attempt. Incidentally if you want to view it is maybe best to view in high definition on vimeo.</p>
<p>I have added a <a href="http://www.liamdevine.co.uk/blog/wp-content/uploads/2009/12/roykata.zip">download</a> which includes the build script, two source files and the Xcode language specification file, more details of where to place the specification file is <a href="http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeWorkspace/100-The_Text_Editor/text_editor.html#//apple_ref/doc/uid/TP40002679-SW43">available</a> on developer.apple. Something I noticed about watching the screen cast back is Xcode&#8217;s code completion for SC++L is really poor, IIRC the only suggestion in the whole the kata is for stringstream&#8217;s method &#8220;tellg&#8221;. It would be interesting to see how much more productive I am using an IDE I have used for years such as Visual Studio.</p>
<p>Finally if anybody has any comments either positive or negative then please do feel free.</p>
<ol>
<li>Create a simple String calculator with a method int Add(string numbers)
<ol>
<li>The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0)<br />
for example “” or “1” or “1,2”</li>
<li>Start with the simplest test case of an empty string and move to 1 and two numbers</li>
<li>Remember to solve things as simply as possible so that you force yourself to write tests you did not think about</li>
<li>Remember to refactor after each passing test</li>
</ol>
</li>
<li>Allow the Add method to handle an unknown amount of numbers</li>
<li>Allow the Add method to handle new lines between numbers (instead of commas).
<ol>
<li>the following input is ok:  “1\n2,3”  (will equal 6)</li>
<li>the following input is NOT ok:  “1,\n”</li>
<li>Make sure you only test for correct inputs. there is no need to test for invalid inputs for these katas</li>
</ol>
</li>
<li>Allow the Add method to handle a different delimiter:
<ol>
<li>to change a delimiter, the beginning of the string will contain a separate line that looks like this:<br />
“//[delimiter]\n[numbers…]” for example “//;\n1;2” should return three where the default delimiter is ‘;’</li>
<li>the first line is optional. all existing scenarios should still be supported</li>
</ol>
</li>
<li>Calling Add with a negative number will throw an exception “negatives not allowed” - and the negative that was passed.</li>
</ol>
<p><object width="400" height="320" data="http://www.vimeo.com/moogaloop.swf?clip_id=8446999&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00adef" type="application/x-shockwave-flash"><param name="quality" value="best" /><param name="scale" value="showAll" /><param name="allowfullscreen" value="true" /><param name="wmode" value="transparent" /><param name="src" value="http://www.vimeo.com/moogaloop.swf?clip_id=8446999&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00adef" /></object></p>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2009/12/string-calculator-kata/#comments" thr:count="6" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2009/12/string-calculator-kata/feed/atom/" thr:count="6" />
		<thr:total>6</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2009/12/string-calculator-kata/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[std::fstream]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/1ijehMHdwJU/" />
		<id>http://www.liamdevine.co.uk/blog/?p=78</id>
		<updated>2009-09-30T15:04:47Z</updated>
		<published>2009-05-07T23:39:25Z</published>
				<summary type="html"><![CDATA[




std::fstream f(&#34;filename&#34;,std::ios_base::binary &#124; std::ios_base::in &#124; std::ios_base::out);
A version of the above code was posted on a website and the poster inquired.
Why doesn&#8217;t this just open a binary file and if it&#8217;s not there create one?
I vaguely remembered something about this instance and at first I thought it was in relation to where data would be written [...]]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2009/05/stdfstream/"><![CDATA[<div class="mceTemp">
<dl id="attachment_84" class="wp-caption aligntop" style="width: 310px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-84" title="question-mark" src="http://www.liamdevine.co.uk/blog/wp-content/uploads/2009/05/question-mark.png" alt="Hmmm" width="300" height="375" /></dt>
</dl>
</div>
<pre class="brush: cpp;">std::fstream f(&quot;filename&quot;,std::ios_base::binary | std::ios_base::in | std::ios_base::out);</pre>
<p>A version of the above code was posted on a website and the poster inquired.</p>
<blockquote><p>Why doesn&#8217;t this just open a binary file and if it&#8217;s not there create one?</p></blockquote>
<p>I vaguely remembered something about this instance and at first I thought it was in relation to where data would be written to. Replying I wrote that adding the &#8220;trunc&#8221; flag would create the file if needed <em>[1]</em> but also truncate the file as the flag would suggest. Once I  had actually  thought about it I came to the realisation this was just nonsense, but there was a reason for my madness.</p>
<p>Although the C++ standard does not mention anything about this, that I can find, I believe it is due to C&#8217;s<a title="fopen doc" href="http://www.cplusplus.com/reference/clibrary/cstdio/fopen/"> fopen</a> modes and that would make sense. Would a combination of both the out and in flags be equivalent to &#8220;r+&#8221; or &#8220;w+&#8221;? Personally I suspect that the default for this situation is &#8220;r+&#8221; and by adding the truncate flag it becomes &#8220;w+&#8221;.</p>
<p>Yet I wonder if this is reliable across all platforms?</p>
<p><em>[1] If you have the correct privalages and the location is not on a read only disc etc.</em></p>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2009/05/stdfstream/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2009/05/stdfstream/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2009/05/stdfstream/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[Interesting C++ error.]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/3FJQ11i4cNs/" />
		<id>http://www.liamdevine.co.uk/blog/?p=43</id>
		<updated>2009-05-08T12:25:16Z</updated>
		<published>2009-04-06T14:08:23Z</published>
				<summary type="html"><![CDATA[
Whilst compiling code using g++ I came across an error that a static constant member was not defined. The member in question was of integer type being defined in-line in the class, I took one look and could see the error even thought I had never personally come into contact with this before. How? Well [...]]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2009/04/interesting-c-error/"><![CDATA[<p><img class="alignleft size-full wp-image-58" title="picard-facepalm" src="http://www.liamdevine.co.uk/blog/wp-content/uploads/2009/04/picard-facepalm.png" alt="picard-facepalm" width="300" height="197" /></p>
<p>Whilst compiling code using g++ I came across an error that a static constant member was not defined. The member in question was of integer type being defined in-line in the class, I took one look and could see the error even thought I had never personally come into contact with this before. How? Well I am a bit of a geek when it comes to the standard and often read it so that I can produce standard conforming (or better conforming) code.</p>
<p>Whilst writing this post I tried to create a minimal example which shows the error; yet I can not produce a simple example that fails so the code posted here is only to demonstration code. invalid_id is the point of interest</p>
<p>Header file:</p>
<pre class="brush: cpp;">namespace Bar
{
	typedef unsigned int Id;
}
class Foo
{
public:
	typedef Bar::Id Id;
	static const Id invalid_id = Id(~0);
	Foo(Id id);
	Id m_id;
};

Foo* foo_create();</pre>
<p>Source file:</p>
<pre class="brush: cpp;">Foo::Foo(Id id):m_id(id){}
Foo* foo_create()
{
	return new Foo(Foo::invalid_id);
}</pre>
<p>The problem is that according to the standard [1] an integral static constant class member can be declared and initialised in line yet it still requires a separate definition. Until this time neither g++ or MSCV has complained about not having it so I have never included it.</p>
<pre class="brush: cpp;">const Foo::Id Foo::invalid_id;</pre>
<p>Upon inserting the above line in the source file so that g++ would compile and then testing with Visual Studio it produces warnings like the following:</p>
<blockquote><p>warning LNK4006: &#8220;public: static unsigned int const X::Y&#8221; &#8230; already defined in Z.obj; second definition ignored</p></blockquote>
<p><em>Where X,Y and Z have been substituted in for ease of reading.</em></p>
<p>A couple of these warnings are produced which is fine you can just ignore then as the compiler is doing the same. This is until you get to  linking the library into an executable at which point it then spits out an error.</p>
<blockquote><p>&#8230; error LNK2005: &#8220;public: static unsigned int const X::Y&#8221; &#8230; already defined in Z.obj</p></blockquote>
<p>I have resorted to using the preprocessor to remove it from Visual Studio builds as I feel this is an MSCV error, if you know otherwise please inform me, and the solutions to the problem which MSDN provides do not seem valid for this code.</p>
<p>[1]</p>
<blockquote><p>9.4.2.4</p>
<p>If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression (5.19). In that case, the member can appear in integral constant expressions. The member shall still be defined in a namespace scope if it is used in the program and the namespace scope definition shall not contain an initializer.</p></blockquote>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2009/04/interesting-c-error/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2009/04/interesting-c-error/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2009/04/interesting-c-error/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[What should I do?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/o8dllj7RMTI/" />
		<id>http://www.liamdevine.co.uk/blog/?p=35</id>
		<updated>2009-03-28T03:32:57Z</updated>
		<published>2009-03-28T03:30:36Z</published>
				<summary type="html"><![CDATA[This is a WTF moment which happened to me whilst trying to save a Power Point presentation from GDC. I was a little confused on what action to take.

]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2009/03/what-should-i-do/"><![CDATA[<p>This is a <a href="http://thedailywtf.com/Default.aspx" target="_blank">WTF</a> moment which happened to me whilst trying to save a Power Point presentation from GDC. I was a little confused on what action to take.</p>
<p><img class="aligncenter size-full wp-image-37" title="confused_power_point" src="http://www.liamdevine.co.uk/blog/wp-content/uploads/2009/03/confused1.png" alt="confused_power_point" width="464" height="300" /></p>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2009/03/what-should-i-do/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2009/03/what-should-i-do/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2009/03/what-should-i-do/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[glEnd(GL_FIXED_FUNCTION_PIPELINE)]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/1URZKyIEEnA/" />
		<id>http://www.liamdevine.co.uk/blog/?p=22</id>
		<updated>2009-03-26T18:08:47Z</updated>
		<published>2009-03-25T22:45:44Z</published>
				<summary type="html"><![CDATA[
Well not quite.
Yesterday saw the release of the new OpenGL 3.1 specification, actually they released two. One which has the fixed function removed and the other which exposes an extension string GL_ARB_compatibility, which if supported by your driver  indicates that the driver has backward support. Nvidia were fast out of the block announcing their Beta [...]]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2009/03/glendgl_fixed_function_pipeline/"><![CDATA[<p><img class="size-full wp-image-31" title="glEnd" src="http://www.liamdevine.co.uk/blog/wp-content/uploads/2009/03/glend.png" alt="glEnd" width="300" height="224" /></p>
<p>Well not quite.<br />
Yesterday saw the release of the new OpenGL 3.1 <a title="3.1 spec" href="http://www.opengl.org/registry/doc/glspec31.20090324.pdf" target="_blank">specification</a>, actually they released <a title="GL_ARB_compatibility spec" href="http://www.opengl.org/registry/doc/glspec31undep.20090324.pdf" target="_blank">two</a>. One which has the fixed function removed and the other which exposes an extension string GL_ARB_compatibility, which if supported by your driver  indicates that the driver has backward support. Nvidia were fast out of the block announcing their <a title="OpenGL 3.1 Beta driver" href="http://developer.nvidia.com/object/opengl_3_driver.html" target="_blank">Beta OpenGL 3.1 driver</a> which supports the extension string, as to whether AMD/ATI will support it is yet to be seen. So if you are not using shaders now is as good a time as any to learn, speaking of which Khronos released the new specification to <a title="GLSL" href="http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf" target="_blank">GLSL</a> last month. For more details see the specifications or the Khronos <a title="Khronos 3.1 press release" href="http://www.khronos.org/news/press/releases/khronos-releases-streamlined-opengl-3.1-specification/" target="_blank">press release</a>.</p>
<p><span style="text-decoration: line-through;">DirectX</span> XNA also released/announced a couple of goodies yesterday including the <a title="Microsoft download page" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=24a541d6-0486-4453-8641-1eee9e21b282&amp;displaylang=en" target="_blank">March DirectX SDK</a> and <a title="Gamasutra article" href="http://www.gamasutra.com/php-bin/news_index.php?story=22877" target="_blank">XNA 3.1</a> (is this version number a coincidence? ) .</p>
<p>Update:</p>
<p>ATI have confirmed that they will be supporting the GL_ARB_compatibility extension.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2009/03/glendgl_fixed_function_pipeline/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2009/03/glendgl_fixed_function_pipeline/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2009/03/glendgl_fixed_function_pipeline/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Liam</name>
						<uri>http://liamdevine.co.uk</uri>
					</author>
		<title type="html"><![CDATA[Win32 window title.]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LiamdevinecoukBlog/~3/u-AqlaQz_T8/" />
		<id>http://www.liamdevine.co.uk/blog/?p=14</id>
		<updated>2009-03-23T18:35:38Z</updated>
		<published>2009-03-23T18:30:12Z</published>
				<summary type="html"><![CDATA[I do not know at what point my Win32 window creation code changed but I have been trying to track a bug which until just now I was unable to find the source. I sub-class the window to allow the message procedure function to be a class member and therefore attaching the this pointer in [...]]]></summary>
		<content type="html" xml:base="http://www.liamdevine.co.uk/blog/2009/03/win32-window-title/"><![CDATA[<p>I do not know at what point my Win32 window creation code changed but I have been trying to track a bug which until just now I was unable to find the source. I sub-class the window to allow the message procedure function to be a class member and therefore attaching the this pointer in <a title="msdn docs" href="http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx" target="_blank">CreateWindowEx</a>. I had the correct flags set for the <a href="http://msdn.microsoft.com/en-us/library/ms632600(VS.85).aspx" target="_blank">style</a> so that the window had a title bar, yet the title was not being shown and the only way I could hack around it was to send a WM_SETTEXT to the window. The problem was due to the handling of the <a title="msdn docs" href="http://msdn.microsoft.com/en-us/library/ms632635(VS.85).aspx">WM_NCCREATE</a> message.The msdn documents state:</p>
<blockquote><p>If an application processes this message, it should return TRUE to continue creation of the window. If the application returns FALSE, the CreateWindow or CreateWindowEx function will return a NULL handle.</p></blockquote>
<p>What if fails to state is that the message needs to be passed to the default window procedure or a window title is not shown. I do not know if this is the only side effect which happens but it was the only noticeable one I could find.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://www.liamdevine.co.uk/blog/2009/03/win32-window-title/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.liamdevine.co.uk/blog/2009/03/win32-window-title/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.liamdevine.co.uk/blog/2009/03/win32-window-title/</feedburner:origLink></entry>
	</feed>

