<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Generic Function Pointers In C And Void *</title>
	<atom:link href="http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html</link>
	<description>Making Your Code Faster, Stronger, Safer…</description>
	<lastBuildDate>Thu, 18 Feb 2010 05:11:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Nonce</title>
		<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-3479</link>
		<dc:creator>Nonce</dc:creator>
		<pubDate>Fri, 22 Jan 2010 21:16:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-3479</guid>
		<description>You didn&#039;t actually mention what systems have a difference sized void and function pointer in C.  What systems are these?  OS/400?  VAX/VMS?  I&#039;ve never heard of such a system.</description>
		<content:encoded><![CDATA[<p>You didn&#8217;t actually mention what systems have a difference sized void and function pointer in C.  What systems are these?  OS/400?  VAX/VMS?  I&#8217;ve never heard of such a system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shantanu Goel</title>
		<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-193</link>
		<dc:creator>Shantanu Goel</dc:creator>
		<pubDate>Tue, 24 Feb 2009 10:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-193</guid>
		<description>@Sean: I don&#039;t think that would be portable because data and function pointer sizes might differ on different architectures and might lead to truncation of the address and information once lost in such a case (by using void * for a function pointer) can not be recovered by the trick that you mentioned.</description>
		<content:encoded><![CDATA[<p>@Sean: I don&#8217;t think that would be portable because data and function pointer sizes might differ on different architectures and might lead to truncation of the address and information once lost in such a case (by using void * for a function pointer) can not be recovered by the trick that you mentioned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-188</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Mon, 23 Feb 2009 19:53:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-188</guid>
		<description>Another way to get a function pointer from a void * is to cast your function pointer to a void ** and dereference it.  Lame example below.

int call_fp_from_vp(void *vp)
{
int (*fp)(int);

*(void **)(&amp;fp) = vp;

return fp(0);
}</description>
		<content:encoded><![CDATA[<p>Another way to get a function pointer from a void * is to cast your function pointer to a void ** and dereference it.  Lame example below.</p>
<p>int call_fp_from_vp(void *vp)<br />
{<br />
int (*fp)(int);</p>
<p>*(void **)(&amp;fp) = vp;</p>
<p>return fp(0);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: guruwars</title>
		<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-31</link>
		<dc:creator>guruwars</dc:creator>
		<pubDate>Fri, 02 Jan 2009 00:42:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-31</guid>
		<description>In C or just a simple unit type case, union is a good choice, but in C++, with complex type would not be preferred because of wasting of memory. At big size structure, how about using inheritance, i think.</description>
		<content:encoded><![CDATA[<p>In C or just a simple unit type case, union is a good choice, but in C++, with complex type would not be preferred because of wasting of memory. At big size structure, how about using inheritance, i think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shantanu Goel</title>
		<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-13</link>
		<dc:creator>Shantanu Goel</dc:creator>
		<pubDate>Tue, 02 Dec 2008 07:38:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-13</guid>
		<description>@Vikas: Yes, M1 needs to know the exact prototype while caling it, hence it needs to know it either statically or through some macro mumbo-jumbo (can&#039;t do it through enums). The advantage here is that the registration api remains constant, and the actual calling part, which is anyways dependent on the type of module, will typecast it appropriately before calling. (Think of a layer that interacts with various drivers to collect events from them and provide different notifications to upper layers)
About far, it has many issues, as in the function being called may not actually be far, using this will unnecessarily complicate things for the compiler and your programs will slow down. There won&#039;t be any type checking as well. And most importantly, far is non-standard, so you can&#039;t even rely on it while moving from one compiler/platform to another.</description>
		<content:encoded><![CDATA[<p>@Vikas: Yes, M1 needs to know the exact prototype while caling it, hence it needs to know it either statically or through some macro mumbo-jumbo (can&#8217;t do it through enums). The advantage here is that the registration api remains constant, and the actual calling part, which is anyways dependent on the type of module, will typecast it appropriately before calling. (Think of a layer that interacts with various drivers to collect events from them and provide different notifications to upper layers)<br />
About far, it has many issues, as in the function being called may not actually be far, using this will unnecessarily complicate things for the compiler and your programs will slow down. There won&#8217;t be any type checking as well. And most importantly, far is non-standard, so you can&#8217;t even rely on it while moving from one compiler/platform to another.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vikas</title>
		<link>http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-11</link>
		<dc:creator>Vikas</dc:creator>
		<pubDate>Tue, 25 Nov 2008 19:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/2008/11/25/generic-function-pointers-in-c-and-void.html#comment-11</guid>
		<description>Hmm....I am still not sure how would M1 get to know the version of the callback to call. I mean suppose M2 passes a callback of type (int (*)(int)) and M3 passes (char (*)(char)). Both of then cast it to (void (*)(void)) while passing to M1 but M1 has no idea which version to cast it back to??? I think the registration API would at least need something like enum { (int (*)(int)), (char (*)(char))} reg_fn_callback_type; to be passed to it???

Moreover, isn&#039;t FAR* good enough with a right-type-enum? I mean is that a compiler dependent type? Or is it that my dream which ended with TurboC++ :) ?</description>
		<content:encoded><![CDATA[<p>Hmm&#8230;.I am still not sure how would M1 get to know the version of the callback to call. I mean suppose M2 passes a callback of type (int (*)(int)) and M3 passes (char (*)(char)). Both of then cast it to (void (*)(void)) while passing to M1 but M1 has no idea which version to cast it back to??? I think the registration API would at least need something like enum { (int (*)(int)), (char (*)(char))} reg_fn_callback_type; to be passed to it???</p>
<p>Moreover, isn&#8217;t FAR* good enough with a right-type-enum? I mean is that a compiler dependent type? Or is it that my dream which ended with TurboC++ <img src='http://www.safercode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
