<?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>Yuriy O&#039;Donnell&#039;s blog &#187; Coding</title>
	<atom:link href="http://kayru.org/entry/category/coding/feed" rel="self" type="application/rss+xml" />
	<link>http://kayru.org</link>
	<description>computer graphics, gamedev, etc.</description>
	<lastBuildDate>Sun, 27 Jun 2010 01:09:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Register assignment in HLSL</title>
		<link>http://kayru.org/entry/89</link>
		<comments>http://kayru.org/entry/89#comments</comments>
		<pubDate>Sun, 27 Jun 2010 01:08:32 +0000</pubDate>
		<dc:creator>kayru</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">http://kayru.org/?p=89</guid>
		<description><![CDATA[When you are manually assigning shader constants to registers (using a &#8216;register&#8217; keyword), those registers are also taken out of the automatic assignment pool. This means that constants that don&#8217;t have explicit registers will never overlap with ones that do even if latter are not used in the shader. And so code like this: float4 [...]]]></description>
			<content:encoded><![CDATA[<p>When you are manually assigning shader constants to registers (using a &#8216;register&#8217; keyword), those registers are also taken out of the automatic assignment pool.<br />
This means that constants that don&#8217;t have explicit registers will never overlap with ones that do even if latter are not used in the shader.<br />
And so code like this:<br />
<code>float4 c0 : register(c0);<br />
float4 c1 : register(c2);<br />
float4 c2;<br />
float4 main():POSITION<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return c2;<br />
}</code></p>
<p>Will compile into this:<br />
<code>vs_2_0<br />
mov oPos, <b>c1</b></code></p>
<p>This is a pretty small thing, but still quite convenient and useful to know.</p>
]]></content:encoded>
			<wfw:commentRss>http://kayru.org/entry/89/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ gotchas</title>
		<link>http://kayru.org/entry/33</link>
		<comments>http://kayru.org/entry/33#comments</comments>
		<pubDate>Sat, 02 May 2009 18:47:52 +0000</pubDate>
		<dc:creator>kayru</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://kayru.org/?p=33</guid>
		<description><![CDATA[Today I&#8217;m going to write about virtual function hiding. Consider the following code: #include &#60;stdio.h&#62; class Foo { public: virtual void fun(int) { printf("A"); } virtual void fun(bool) { printf("B"); fun(int()); } }; class Bar : public Foo { public: virtual void fun(int) { printf("C"); } }; int main() { Bar b; b.fun(bool()); return 0; [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m going to write about virtual function hiding.</p>
<p>Consider the following code:</p>
<pre style="color:#000000;background:#ffffff;"><span style="color:#004a43; ">#</span><span style="color:#004a43; ">include </span><span style="color:#800000; ">&lt;</span><span style="color:#40015a; ">stdio.h</span><span style="color:#800000; ">&gt;</span>

<span style="color:#800000; font-weight:bold; ">class</span> Foo
<span style="color:#800080; ">{</span>
<span style="color:#800000; font-weight:bold; ">public</span><span style="color:#e34adc; ">:</span>
    <span style="color:#800000; font-weight:bold; ">virtual</span> <span style="color:#800000; font-weight:bold; ">void</span> fun<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">int</span><span style="color:#808030; ">)</span>
    <span style="color:#800080; ">{</span>
        printf<span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">A</span><span style="color:#800000; ">"</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
    <span style="color:#800080; ">}</span>
    <span style="color:#800000; font-weight:bold; ">virtual</span> <span style="color:#800000; font-weight:bold; ">void</span> fun<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">bool</span><span style="color:#808030; ">)</span>
    <span style="color:#800080; ">{</span>
        printf<span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">B</span><span style="color:#800000; ">"</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
        fun<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">int</span><span style="color:#808030; ">(</span><span style="color:#808030; ">)</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
    <span style="color:#800080; ">}</span>
<span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>

<span style="color:#800000; font-weight:bold; ">class</span> Bar <span style="color:#800080; ">:</span> <span style="color:#800000; font-weight:bold; ">public</span> Foo
<span style="color:#800080; ">{</span>
<span style="color:#800000; font-weight:bold; ">public</span><span style="color:#e34adc; ">:</span>
    <span style="color:#800000; font-weight:bold; ">virtual</span> <span style="color:#800000; font-weight:bold; ">void</span> fun<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">int</span><span style="color:#808030; ">)</span>
    <span style="color:#800080; ">{</span>
        printf<span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">C</span><span style="color:#800000; ">"</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
    <span style="color:#800080; ">}</span>
<span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>

<span style="color:#800000; font-weight:bold; ">int</span> <span style="color:#400000; ">main</span><span style="color:#808030; ">(</span><span style="color:#808030; ">)</span>
<span style="color:#800080; ">{</span>    

    Bar b<span style="color:#800080; ">;</span>
    b<span style="color:#808030; ">.</span>fun<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">bool</span><span style="color:#808030; ">(</span><span style="color:#808030; ">)</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>    

    <span style="color:#800000; font-weight:bold; ">return</span> <span style="color:#008c00; ">0</span><span style="color:#800080; ">;</span>
<span style="color:#800080; ">}</span></pre>
<p>What will be written to the console?</p>
<p><span id="more-33"></span> You will see &#8220;C&#8221;.</p>
<p>Overloading virtual function fun() in class Bar hides all other versions of functions with that name. Combined with implicit type casting, this may lead to undesirable behaviour.</p>
<p>This is the same problem as you get with multiple inheritance. To fix it, we need to explicitly specify what we want to inherit by adding the following statement to Bar class declaration:<br />
class Bar<br />
{<br />
&#8230;<br />
public:<br />
<strong>using Foo::fun;</strong><br />
&#8230;<br />
}</p>
<p>With this statement, output becomes &#8220;BC&#8221;.</p>
<p>Neither VC++ 8 nor GCC 4 will warn about this. Therefore, regular linting is a must to flush-out bugs like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://kayru.org/entry/33/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
