<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Anything and Everything</title>
	<atom:link href="http://cnaphro.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cnaphro.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sat, 02 Apr 2011 06:41:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='cnaphro.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Anything and Everything</title>
		<link>http://cnaphro.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://cnaphro.wordpress.com/osd.xml" title="Anything and Everything" />
	<atom:link rel='hub' href='http://cnaphro.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Error CS1504: unspecified error</title>
		<link>http://cnaphro.wordpress.com/2011/04/02/error-cs1504-unspecified-error/</link>
		<comments>http://cnaphro.wordpress.com/2011/04/02/error-cs1504-unspecified-error/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 06:40:52 +0000</pubDate>
		<dc:creator>cnaphro</dc:creator>
				<category><![CDATA[Csharp]]></category>

		<guid isPermaLink="false">http://cnaphro.wordpress.com/?p=95</guid>
		<description><![CDATA[So, I just spent the night doing some work on the NetGore engine (www.netgore.com) and when it finally came to build and test the stuff I&#8217;d been working on I got the following message from the c# compiler: error CS1504: &#8230; <a href="http://cnaphro.wordpress.com/2011/04/02/error-cs1504-unspecified-error/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cnaphro.wordpress.com&amp;blog=8041058&amp;post=95&amp;subd=cnaphro&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, I just spent the night doing some work on the NetGore engine (<a href="http://www.netgore.com">www.netgore.com</a>) and when it finally came to build and test the stuff I&#8217;d been working on I got the following message from the c# compiler:</p>
<pre>error CS1504: Source file 'C:\...\ParticleLinearScaleModifier.cs' could not be opened ('Unspecified error ')</pre>
<p>This is not just a rant about the how ridiculous that error message is but hopefully, will give youat least  ONE idea on how to fix it (considering its such a vague error i&#8217;ll do my best).</p>
<p>In Visual Studio you can move files around within the solution explorer, some how, i have absolutely no idea how, I&#8217;d managed to move all of the files, including directory structure into another directory.  However nothing was shown in the solution explorer to be different, i.e. the directory structure looks exactly as it should.  but on going to Windows explorer i found that all the files were in a different location.</p>
<p>Moving these files back and reverting using subversion fixed my problem.  But why do Microsoft put in unspecified errors&#8230;?  So helpful Microsoft are :/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cnaphro.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cnaphro.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cnaphro.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cnaphro.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cnaphro.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cnaphro.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cnaphro.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cnaphro.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cnaphro.wordpress.com&amp;blog=8041058&amp;post=95&amp;subd=cnaphro&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cnaphro.wordpress.com/2011/04/02/error-cs1504-unspecified-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3e352c92bbd3f3f36ee2fa20e810bf6e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cnaphro</media:title>
		</media:content>
	</item>
		<item>
		<title>C# types</title>
		<link>http://cnaphro.wordpress.com/2011/01/14/c-types/</link>
		<comments>http://cnaphro.wordpress.com/2011/01/14/c-types/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 16:06:23 +0000</pubDate>
		<dc:creator>cnaphro</dc:creator>
				<category><![CDATA[Csharp]]></category>

		<guid isPermaLink="false">http://cnaphro.wordpress.com/?p=76</guid>
		<description><![CDATA[I&#8217;ve been on and off programming in my preferred language C# having to switch to Java and Groovy for university, however recently i decided to do some interesting research into the C# language and the CLR about stuff i never &#8230; <a href="http://cnaphro.wordpress.com/2011/01/14/c-types/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cnaphro.wordpress.com&amp;blog=8041058&amp;post=76&amp;subd=cnaphro&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been on and off programming in my preferred language C# having to switch to Java and Groovy for university, however recently i decided to do some interesting research into the C# language and the CLR about stuff i never thought about before.</p>
<h4>Creating a new type</h4>
<p>The C# languages types are all derived from the FCL (Framework class library) type: System.Object.  As all types are derived from the Object type and the CLR requires all objects to be created with the &#8220;new&#8221; operator objects are declared and created as follows:</p>
<p><code>System.Object obj = new System.Object()</code></p>
<p>The new operator calculates the number of bytes required by all the instanced fields in the type and all derived types up to and including System.Object.  Every Object added to the heap requires additional members used by the CLR to manage the object &#8211; sync block index and the object pointer .  The additional bytes for these members are added to the total size.  The CLR then allocates this memory from the managed heap and then the CLR initializes the type object pointer and sync block index members.  Finally the constructor is called.  Each constructor of the derived types are responsible for initializing the instanced fields of that particular constructors type. Finally a reference to the newly initialized type is returned and stored.</p>
<h4>Primitve types</h4>
<p>C# reserves certain keywords that represent commonly used types.  These types are known as primitive types.  Primitive types are always synonyms of types described in the FCL.  For instance in the following example exactly the same intermediate language code would be created:<br />
<code><br />
int _integer = 0;                  // Creates a new instance of the System.Int32 type.<br />
int _integer = new System.Int32(); // Creates a new instance of the System.Int32 type.<br />
System.Int32 _integer = new int(); // Create a new instance of the System.Int32 type.</code></p>
<p>All of the above declarations and initialization are interchangeable.</p>
<p>Keywords are defined by the specific language specification and implemented by the compiler.  The problem with this is that different languages specifications will always vary slightly and have the possibilities to cause confusion when reading code across languages.  For example in C# the long primitive maps to System.Int64 where as in managed C++ the long primitive is treated as an Int32.</p>
<p>Primitive mappings do not change when switching between 32 bit and 64 bit systems using .net as they might do in unmanaged C++ or C.</p>
<h5>Primitive type overflow: Checked and Unchecked operations</h5>
<p>Consider the following code:</p>
<p><code> byte _byte = 57;<br />
_byte = (byte) (_byte + 200);</code></p>
<p>What would the value in _byte be after the second line of execution?</p>
<p>_byte would be equal to 1. Note that the type cast performed in the second line is necessary as the operand values are expanded to Int32 values.</p>
<p>Sometimes this behaviour is desired, but more often than not can cause subtle bugs.  The IL generated by C# will by default have overflow checking turned off, this means the IL code runs slightly faster.  However what if we do need to check for overflows and throw exceptions when they occur?  C# provides &#8220;checked&#8221; and &#8220;unchecked&#8221; operators.  The checked operator will throw an OverflowException if an overflow occurs, and the unchecked operator will allow the overflow to occur.  These can also be set in statement blocks.</p>
<p>Checked example:<br />
<code>Byte _byte = 57;<br />
_byte = checked((Byte)( _byte + 200));<br />
</code></p>
<p>This will throw an exception with the message:  &#8221;Arithmetic operation resulted in an overflow.&#8221;  Whereas the following code will execute without an error being raised:</p>
<p><code>Byte _byte = 57;<br />
_byte = unchecked((Byte)(_byte + 200));</code></p>
<h4>Value types: struct</h4>
<p>In C# value types are defined using struct.  Value types are allocated on the stack, along with references to objects on the managed heap.  Consider the following code:<br />
<code><br />
struct AValue { int X; }<br />
...<br />
AValue _value = new AValue();<br />
_value.X = 50;<br />
AValue _newValue = _value;<br />
_newValue.X = 100;<br />
Console.WriteLine(_value.X);      // Outputs 50.<br />
Console.WriteLine(_newValue.X);   // Outputs 100.</code></p>
<p>Here a struct : AValue is defined.  In the main section of the code we create an AValue type called _value which we then copy to the _newValue variable and allocate new space on the thread stack.  This point is important, the fact that we have allocated new space on the stack and copied the members to a completely new instance of the AValue type.  This is a fundamental difference between the use of value types and reference types (see next section for reference types).</p>
<h5>Boxing and unboxing value types</h5>
<p>Sometimes it may be necessary to use a reference to an instance of a value type.  Consider the following code:<br />
<code><br />
struct SomeVal { public int x; }<br />
class SomeClass<br />
{<br />
public Object _theObject;<br />
public void Get(object param)<br />
{<br />
_theObject = param;<br />
}<br />
}</code></p>
<p><code>...</code></p>
<p><code>SomeClass _ref = new SomeClass();<br />
SomeVal _val = new SomeVal();<br />
_val.x = 2000;<br />
_ref.Get(_val);</code></p>
<p>You can see that the SomeClass object requires a reference to an object on the managed heap, however we are trying to pass a value type as a parameter which is stored on the stack.  For the above example to work the value type must be converted to a managed object stored on the heap. Boxing allows us to do this.</p>
<p>Boxing works by allocating memory to the heap required by the value type&#8217;s fields (plus the two additional fields required for objects on the managed heap &#8211; object pointer and sync block index).  Then the value types fields are copied into the allocated heap memory.  And finally an object reference is returned.  Essentially you are converting you&#8217;re value type to a reference to a type on the managed heap.  This can carry some extra overhead in terms of cpu cycles and memory usage as we are allocating extra space on the heap as well as the stack.</p>
<p>Consider the following example (following on from the previous code example):</p>
<p><code>SomeVal _val2 = (SomeVal)_ref._theObject;</code></p>
<p>Here we are taking a reference and trying to place it in a value type instance.  For this to work we need to copy fields contained on the managed heap into the value type fields on the stack.  This operation is known as unboxing.</p>
<p>Boxing in some situations can be avoided by using generics.</p>
<h4>Reference types</h4>
<p>The last type that I haven&#8217;t talked about yet is reference types.  Reference types are always allocated on the managed heap. Unlike value types, if you remember which are stored on the thread stack.  When a new reference type is created a memory address is stored on the stack as a reference to the object on the managed heap. Reference types can carry some performance overheads.   Which is why the CLR provides value types as lighter weighted variables.  A type declared using the class keyword is a reference type and a type declared using the struct keyword is a value type (enums are also derived from value types).</p>
<p>&nbsp;</p>
<p>That&#8217;s all for now.  I&#8217;ve been playing around with C# a bit more and have some more interesting findings to post soon.  Watch this space.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cnaphro.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cnaphro.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cnaphro.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cnaphro.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cnaphro.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cnaphro.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cnaphro.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cnaphro.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cnaphro.wordpress.com&amp;blog=8041058&amp;post=76&amp;subd=cnaphro&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cnaphro.wordpress.com/2011/01/14/c-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3e352c92bbd3f3f36ee2fa20e810bf6e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cnaphro</media:title>
		</media:content>
	</item>
	</channel>
</rss>
