<?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>Alteridem Consulting &#187; C++</title>
	<atom:link href="http://www.alteridem.net/category/cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alteridem.net</link>
	<description>Software by Design</description>
	<lastBuildDate>Fri, 02 Sep 2011 14:21:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The dangers of Macros</title>
		<link>http://www.alteridem.net/2010/07/21/the-dangers-of-macros/</link>
		<comments>http://www.alteridem.net/2010/07/21/the-dangers-of-macros/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 15:02:44 +0000</pubDate>
		<dc:creator>Robert Prouse</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Tips'n'Tricks]]></category>

		<guid isPermaLink="false">http://www.alteridem.net/?p=65</guid>
		<description><![CDATA[Another developer came to me with a problem today that he couldn’t figure out. He couldn’t believe what he was seeing in the debugger and needed a second set of eyes. He had a line of code like the following; return max( eRetVal, GetNumber() ); While debugging, he noticed that he was stepping into the [...]]]></description>
			<content:encoded><![CDATA[<p>Another developer came to me with a problem today that he couldn’t figure out. He couldn’t believe what he was seeing in the debugger and needed a second set of eyes. He had a line of code like the following;</p>
<pre name="code" class="cpp">return max( eRetVal, GetNumber() );</pre>
<p>While debugging, he noticed that he was stepping into the GetNumber() method twice, and in his code, it had side-effects. We both puzzled over it for awhile. We looked at the disassembly and sure enough, it was getting called twice, but why? Then it hit me, <b>max</b> is a macro, not a function. If you go to the definition of <b>max</b>, you find;</p>
<pre name="code" class="cpp">#ifndef max
#define max(a,b)            (((a) &gt; (b)) ? (a) : (b))
#endif</pre>
<p>So, if you expand that macro out, the original code gets compiles as;</p>
<pre name="code" class="cpp">return (((eRetVal) &gt; (GetNumber()) ? (eRetVal) : (GetNumber());</pre>
<p>Once the macro is expanded, it is easy to see why the method is called twice. Obviously I have not being doing enough C++ lately. There was a time when I would have seen that immediately as it is the classic example, but I have been working in .NET so long now that I am forgetting all of the little ways that C++ can bite you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alteridem.net/2010/07/21/the-dangers-of-macros/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging C++ Method Parameters</title>
		<link>http://www.alteridem.net/2007/09/11/debugging-c-method-parameters/</link>
		<comments>http://www.alteridem.net/2007/09/11/debugging-c-method-parameters/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 19:20:04 +0000</pubDate>
		<dc:creator>Robert Prouse</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C++/CLR]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.alteridem.net/2007/09/11/debugging-c-method-parameters/</guid>
		<description><![CDATA[New Rule: Make sure your parameter names are consistent between your declarations and definitions in C++. Here is why&#8230; I was trying to debug some C++/CLR code today when I ran into an interesting behavior (bug?) in Visual Studio 2005. I had a breakpoint in the first line of my method which I hit fine. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>New Rule: Make sure your parameter names are consistent between your declarations and definitions in C++.</strong></p>
<p>Here is why&#8230;</p>
<p>I was trying to debug some <strong>C++/CLR</strong> code today when I ran into an interesting behavior (bug?) in <strong>Visual Studio 2005</strong>. I had a breakpoint in the first line of my method which I hit fine. I then tried to inspect the value of the two integers that were passed in. The first one showed up fine when I moused over it, but the second one didn&#8217;t appear. Strange, but I&#8217;ve come to expect that debugging in C++.</p>
<p>The next thing I tried was the Watch window (Ctrl+Alt+W,1). I added both of the parameters. The first showed up fine, but the second said <strong>&#8220;error: identifier &#8216;maxRows&#8217; out of scope.&#8221;</strong> How could it be out of scope, I was on the first line in the method?</p>
<p>Next I looked at the Locals window (Ctrl+Alt+V,L). The parameter was showing up fine there! Then I noticed the difference, the name of the parameter in the locals window wasn&#8217;t pluralized. Sure enough, I looked in the header file and it was spelled <strong>maxRow</strong> there.</p>
<p>It turns out that the debug symbols are taken from the header files, so when you step into a method with parameters that are spelled differently, then you must use the values in the header file to inspect the variables.</p>
<p>Here is an example I mocked up where the parameters were x and y in the header files.</p>
<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="CppDebugging" src="http://www.alteridem.net/wp-content/uploads/2007/09/cppdebugging.jpg" width="443" border="0"> </p>
<p>I also tried this in unmanaged C++ and got the same result.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alteridem.net/2007/09/11/debugging-c-method-parameters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

