<?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; what is name mangling</title>
	<atom:link href="http://weseetips.com/tag/what-is-name-mangling/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>What is Name Mangling and how to disable Name Mangling?</title>
		<link>http://weseetips.com/2008/07/16/what-is-name-mangling-and-how-to-disable-name-mangling/</link>
		<comments>http://weseetips.com/2008/07/16/what-is-name-mangling-and-how-to-disable-name-mangling/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 17:45:26 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[disable name mangling]]></category>
		<category><![CDATA[extern "C"]]></category>
		<category><![CDATA[function overloading]]></category>
		<category><![CDATA[name mangling]]></category>
		<category><![CDATA[vc++ name mangling]]></category>
		<category><![CDATA[Visual C++ name mangling]]></category>
		<category><![CDATA[what is name mangling]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=219</guid>
		<description><![CDATA[What is Name Mangling? Name mangling is the technique used by C++ to generate unique names. C++ uses name mangling to implement function overloading etc. For instance, if you have two overloaded functions, while compiling the source, compiler will internally rename your function to uniquely generated function name. The function name is generated from the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /></p>
<p><span style="text-decoration:underline;"><strong>What is Name Mangling?</strong></span><br />
Name mangling is the technique used by <span style="color:#0000ff;">C++ to generate unique names</span>. C++ uses name mangling to implement <span style="color:#0000ff;">function overloading</span> etc. For instance, if you have two overloaded functions, while compiling the source, compiler will internally rename your function to uniquely generated function name. The function name is generated from the parameter list and a couple of other factors.</p>
<p>Check the links for the name mangling algorithm by Visual C++.<br />
<a title="http://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B_Name_Mangling" href="http://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B_Name_Mangling" target="_blank">http://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B_Name_Mangling</a><br />
<a title="http://www.kegel.com/mangle.html" href="http://www.kegel.com/mangle.html" target="_blank">http://www.kegel.com/mangle.html</a></p>
<p>Have a look at mangled C++ function names below.</p>
<p><img class="alignnone size-full wp-image-221" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/07/namemangling.jpg" alt="" width="510" height="382" /></p>
<p>Well, Name Mangling is nice. <span style="color:#0000ff;">But it have one problem.</span> You <span style="color:#0000ff;">cannot call your exported C++ function from C code.</span> Because, C++ compiler mangles the function name and renames the fuction and exposes the mangled function name. So in order for C source to call C++ function, <span style="color:#0000ff;">you&#8217;ve to disable name mangling</span> for those functions. But how?</p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can disable name mangling by declaring the function as <span style="color:#0000ff;">extern &#8220;C&#8221;</span>. Have a look at the code snippet.</p>
<pre>// Disable name Mangling for single function.
extern "C" void Function( int a, int b );

// Disable name Mangling for group of functions.
extern "C"
{
    void Function1( char a, char  b );
    void Function2( int a, int   b );
    void Function3( float a, float b );
}</pre>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
If you want to get the function name from a mangled name, then have a look at my previous post -<br />
<a title="http://weseetips.com/2008/04/14/name-mangling-how-to-undecorate-a-c-decorated-function-name/" href="http://weseetips.com/2008/04/14/name-mangling-how-to-undecorate-a-c-decorated-function-name/" target="_blank">http://weseetips.com/2008/04/14/name-mangling-how-to-undecorate-a-c-decorated-function-name/</a></p>
<p><img class="alignnone size-medium wp-image-51" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/07/16/what-is-name-mangling-and-how-to-disable-name-mangling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

