<?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>Visual C++ Tips &#187; Warning C4100 unreferenced formal parameter</title>
	<atom:link href="http://weseetips.com/tag/warning-c4100-unreferenced-formal-parameter/feed/" rel="self" type="application/rss+xml" />
	<link>http://weseetips.com</link>
	<description>Gold mine of Visual C++ tricks!</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to Remove Unreferenced Formal Parameter warning?</title>
		<link>http://weseetips.com/2008/11/26/how-to-remove-unreferenced-formal-parameter-warning/</link>
		<comments>http://weseetips.com/2008/11/26/how-to-remove-unreferenced-formal-parameter-warning/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 19:46:57 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Project settings]]></category>
		<category><![CDATA[unreferenced formal parameter]]></category>
		<category><![CDATA[UNREFERENCED_PARAMETER]]></category>
		<category><![CDATA[Warning C4100]]></category>
		<category><![CDATA[Warning C4100 unreferenced formal parameter]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=652</guid>
		<description><![CDATA[Hands on legacy code base is a different kind of game! You have to learn a lot of tricks. During old days, legacy codebases have the compiler default settings. But now, for better error catching, most will switch the warning level to high. Well, did you ever ported your legacy codebase by updating its project [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /></p>
<p><span style="color:#0000ff;">Hands on legacy code base is a different kind of game!</span> You have to learn a lot of tricks. During old days, legacy codebases have the compiler default settings. But now, for better error catching, <span style="color:#0000ff;">most will switch  the warning level to high.</span> Well, did you ever ported your legacy codebase by updating its project settings such as by switching the warning level from Level 3 (default) to Level 4, <span style="color:#0000ff;">most probably you&#8217;ll get this &#8211; <strong>&#8220;Warning C4100: &#8216;Param2&#8242; : unreferenced formal parameter&#8221;</strong>.</span></p>
<p>In most of the case, <span style="color:#0000ff;">it might be some unused stack variable</span>. But in some other cases, <span style="color:#0000ff;">it might be the unused function parameters as well</span>. For instance, if base class have some pure virtual function, we have to implement that, even if we don&#8217;t have any specific implementation for it. In that case, the parameters will not be used and can cause the same warning. Well how to <strong>&#8220;kick out&#8221;</strong> those warnings easily?</p>
<p><img class="alignnone size-full wp-image-660" title="unreferrencedvariablewarning" src="http://weseetips.wordpress.com/files/2008/11/unreferrencedvariablewarning.jpg" alt="unreferrencedvariablewarning" width="510" height="408" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Well, there are two tricks.</p>
<p><span style="text-decoration:underline;"><strong>1) Use the macro &#8211; UNREFERENCED_PARAMETER</strong></span><br />
<span style="color:#0000ff;"> The common trick is to use the macro UNREFERENCED_PARAMETER()</span>. When it expands, <span style="color:#0000ff;">it just assigns the variable to itself. Just like a=a.</span> Which will remove the warning, since the variable is used to assign to itself.</p>
<pre>// The function that derived class was forced to implement,
// since its pure virtual function defined in base.
void CRabbitDialogDlg::Function( bool Param1, bool Param2 )
{
    // Here Param1 and Param2 are not used which will
    // trigger warning. Now they won't.
    UNREFERENCED_PARAMETER( Param1 );
    UNREFERENCED_PARAMETER( Param2 );
}</pre>
<p><span style="text-decoration:underline;"><strong>2) Comment out the variable names.</strong></span><br />
Even though <span style="color:#0000ff;">UNREFERENCED_PARAMETER()</span> serves the need, its <span style="color:#0000ff;">not efficient</span>. isn&#8217;t it? It assigns the variable to itself and thus avoids the warning. Well there is another easy method. <span style="color:#0000ff;">Just comment out the variable name</span>. Check the code snippet below.</p>
<pre>// The function that derived class was forced to implement,
// since its pure virtual function defined in base.
void CRabbitDialogDlg::Function( bool /*Param1*/, bool /*Param2*/ )
{
    // Since the variable name doesn't exist, how compiler can
    // complain that variable is not used. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
In one of my projects, I was forced write an empty implementation for a pure virtual function in derived class. And my client needs zero compilation warning. At that time I really struggled to remove this warning. <img src='http://weseetips.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  <span style="color:#0000ff;">Now when i shared it with you, it feels good!</span></p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.wordpress.com/files/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audiance &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/11/26/how-to-remove-unreferenced-formal-parameter-warning/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

