<?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: Wrapping C++ in ObjC</title>
	<atom:link href="http://robnapier.net/blog/wrapping-c-objc-20/feed" rel="self" type="application/rss+xml" />
	<link>http://robnapier.net/blog/wrapping-c-objc-20</link>
	<description>Mac and iPhone, on the brain</description>
	<lastBuildDate>Thu, 02 Feb 2012 16:51:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Box2D UIView and Objective C C++ Wrapper &#124; CocoaHeads</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-5076</link>
		<dc:creator>Box2D UIView and Objective C C++ Wrapper &#124; CocoaHeads</dc:creator>
		<pubDate>Fri, 14 Jan 2011 19:38:58 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-5076</guid>
		<description>&lt;p&gt;[...] technique rapidement présentée est celle-ci : http://robnapier.net/blog/wrapping-c-objc-20. Le post est un peu vieux, et l&#8217;auteur de ce blog utilise depuis une autre technique, [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] technique rapidement présentée est celle-ci : <a href="http://robnapier.net/blog/wrapping-c-objc-20" rel="nofollow">http://robnapier.net/blog/wrapping-c-objc-20</a>. Le post est un peu vieux, et l&#8217;auteur de ce blog utilise depuis une autre technique, [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-1701</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Wed, 09 Jun 2010 06:44:56 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-1701</guid>
		<description>&lt;p&gt;@Jacob, see my &lt;a href=&quot;http://robnapier.net/blog/wrapping-c-take-2-1-486&quot; rel=&quot;nofollow&quot;&gt;update&lt;/a&gt;. I&#039;ve posted a simple example of this. I&#039;ll post a more complex example (including smart pointers, and more) shortly.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Jacob, see my <a href="http://robnapier.net/blog/wrapping-c-take-2-1-486" rel="nofollow">update</a>. I&#8217;ve posted a simple example of this. I&#8217;ll post a more complex example (including smart pointers, and more) shortly.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Wrapping C++ &#8211; Take 2, Part 1 &#124; Cocoaphony</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-1700</link>
		<dc:creator>Wrapping C++ &#8211; Take 2, Part 1 &#124; Cocoaphony</dc:creator>
		<pubDate>Wed, 09 Jun 2010 06:43:27 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-1700</guid>
		<description>&lt;p&gt;[...] year, I presented an approach to wrapping C++. Since then, I&#8217;ve been introduced to other approaches, particularly from gf who helped me [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] year, I presented an approach to wrapping C++. Since then, I&#8217;ve been introduced to other approaches, particularly from gf who helped me [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-1693</link>
		<dc:creator>Jacob</dc:creator>
		<pubDate>Tue, 08 Jun 2010 09:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-1693</guid>
		<description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Any chance of reposting &quot;http://pastebin.org/207012&quot;?  or providing an equivalent example of the non-trivial constructor here?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi,</p>

<p>Any chance of reposting &#8220;http://pastebin.org/207012&#8243;?  or providing an equivalent example of the non-trivial constructor here?</p>

<p>Thanks</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-1422</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Sat, 08 May 2010 16:56:24 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-1422</guid>
		<description>&lt;p&gt;OK, now I&#039;m seeing it. The key is the use of C++&#039;s ambiguity between structs and classes. By adding a &quot;constructor&quot; to your struct, you got the benefits of a C++ object while allowing it to be defined in the header. No casting at all, and fewer raw pointers to C++ objects. I should be able to wrap shared_ptr&lt;&gt; in there easily as well (which is coming up more often in my code, and has been a bit of a pain). I like this. I&#039;ve got a dozen or so ObjC/C++ wrapper classes to write this month, so I&#039;ll give this a try and see if it&#039;s as handy as it looks. Thanks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>OK, now I&#8217;m seeing it. The key is the use of C++&#8217;s ambiguity between structs and classes. By adding a &#8220;constructor&#8221; to your struct, you got the benefits of a C++ object while allowing it to be defined in the header. No casting at all, and fewer raw pointers to C++ objects. I should be able to wrap shared_ptr&lt;> in there easily as well (which is coming up more often in my code, and has been a bit of a pain). I like this. I&#8217;ve got a dozen or so ObjC/C++ wrapper classes to write this month, so I&#8217;ll give this a try and see if it&#8217;s as handy as it looks. Thanks.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: gf</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-1414</link>
		<dc:creator>gf</dc:creator>
		<pubDate>Fri, 07 May 2010 16:00:53 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-1414</guid>
		<description>&lt;p&gt;I somehow forgot about this discussion, sorry about that. Snippet here:
http://pastebin.org/207012&lt;/p&gt;

&lt;p&gt;For me it has the major advantage that through the wrapping opaque struct i&#039;m in a clean C++-world again regarding object storage.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I somehow forgot about this discussion, sorry about that. Snippet here:
<a href="http://pastebin.org/207012" rel="nofollow">http://pastebin.org/207012</a></p>

<p>For me it has the major advantage that through the wrapping opaque struct i&#8217;m in a clean C++-world again regarding object storage.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-994</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Tue, 23 Feb 2010 17:44:25 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-994</guid>
		<description>&lt;p&gt;I&#039;m not clear how you&#039;re allocating the object for the struct if it has a non-trival constructor (i.e. you need to pass parameters). Can you show an example of this model? As far as helper C++ objects, I have them all the time (mostly listeners), but I don&#039;t see what that has to do with a struct. They don&#039;t need to be passed around as some kind of bundle; I just have multiple pointers in my ObjC class. Again, maybe this would be clearer with some example code of using the opaque pointer.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m not clear how you&#8217;re allocating the object for the struct if it has a non-trival constructor (i.e. you need to pass parameters). Can you show an example of this model? As far as helper C++ objects, I have them all the time (mostly listeners), but I don&#8217;t see what that has to do with a struct. They don&#8217;t need to be passed around as some kind of bundle; I just have multiple pointers in my ObjC class. Again, maybe this would be clearer with some example code of using the opaque pointer.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: gf</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-991</link>
		<dc:creator>gf</dc:creator>
		<pubDate>Tue, 23 Feb 2010 08:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-991</guid>
		<description>&lt;p&gt;&lt;a href=&quot;#comment-985&quot; rel=&quot;nofollow&quot;&gt;@Rob Napier&lt;/a&gt; 
Thanks for the heartache point, that might be a good one (i&#039;ve currently mainly done rather flat Obj-C bridging). But there is no additional malloc/free/new/delete - its still one as you don&#039;t need to hold a pointer to the object in the opaque struct.&lt;/p&gt;

&lt;p&gt;I think we have a misunderstanding though, i didn&#039;t intend to hand the opaque pointer aound, its just for Pimpl.&lt;/p&gt;

&lt;p&gt;Putting other things in there is not only relevant if you pass the pointer - what if you need to additional (helper/secondary) C++ objects to deal with the main object?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="#comment-985" rel="nofollow">@Rob Napier</a> 
Thanks for the heartache point, that might be a good one (i&#8217;ve currently mainly done rather flat Obj-C bridging). But there is no additional malloc/free/new/delete &#8211; its still one as you don&#8217;t need to hold a pointer to the object in the opaque struct.</p>

<p>I think we have a misunderstanding though, i didn&#8217;t intend to hand the opaque pointer aound, its just for Pimpl.</p>

<p>Putting other things in there is not only relevant if you pass the pointer &#8211; what if you need to additional (helper/secondary) C++ objects to deal with the main object?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-985</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Mon, 22 Feb 2010 14:34:36 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-985</guid>
		<description>&lt;p&gt;You should never call &quot;opaque-&gt;cppobj&quot; directly. That access an ivar (opaque) outside of an accessor, which should be avoided whenever possible. There is no single rule that will avoid more heartache then sticking to accessors, and the caller shouldn&#039;t need a special &quot;oh, I use the ivar directly when it&#039;s a C++ wrapper&quot; rule. Special rules are the bane of code review. So in any case it&#039;ll be &quot;self.opaque-&gt;cppobj&quot; which is no better than &quot;self.cppobj,&quot; while adding an additional malloc/free for the struct.&lt;/p&gt;

&lt;p&gt;To the point of putting other things in the struct, this is only significant if you ever hand back pointers to the struct to a caller, and you almost certainly shouldn&#039;t be doing that anyway in ObjC. This makes sense in a C wrapper around C++ (like Core Foundation, and I use this pattern elsewhere), but I still don&#039;t see a benefit in ObjC.&lt;/p&gt;

&lt;p&gt;Do you have any example code that shows how to do this well &lt;em&gt;without&lt;/em&gt; bypassing accessors on the ivars? I think the resulting code is less space efficient, more complicated and gives no greater type safety.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You should never call &#8220;opaque->cppobj&#8221; directly. That access an ivar (opaque) outside of an accessor, which should be avoided whenever possible. There is no single rule that will avoid more heartache then sticking to accessors, and the caller shouldn&#8217;t need a special &#8220;oh, I use the ivar directly when it&#8217;s a C++ wrapper&#8221; rule. Special rules are the bane of code review. So in any case it&#8217;ll be &#8220;self.opaque->cppobj&#8221; which is no better than &#8220;self.cppobj,&#8221; while adding an additional malloc/free for the struct.</p>

<p>To the point of putting other things in the struct, this is only significant if you ever hand back pointers to the struct to a caller, and you almost certainly shouldn&#8217;t be doing that anyway in ObjC. This makes sense in a C wrapper around C++ (like Core Foundation, and I use this pattern elsewhere), but I still don&#8217;t see a benefit in ObjC.</p>

<p>Do you have any example code that shows how to do this well <em>without</em> bypassing accessors on the ivars? I think the resulting code is less space efficient, more complicated and gives no greater type safety.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: gf</title>
		<link>http://robnapier.net/blog/wrapping-c-objc-20/comment-page-1#comment-972</link>
		<dc:creator>gf</dc:creator>
		<pubDate>Sat, 20 Feb 2010 19:39:59 +0000</pubDate>
		<guid isPermaLink="false">http://cocoaphony.wordpress.com/?p=20#comment-972</guid>
		<description>&lt;blockquote cite=&quot;#commentbody-971&quot;&gt;
&lt;strong&gt;&lt;a href=&quot;#comment-971&quot; rel=&quot;nofollow&quot;&gt;gf&lt;/a&gt; :&lt;/strong&gt;The only down-side i can think of is the pointer-indirection in high-performance code – but that can get possibly optimized if there is a proven hot-spot there&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Hm, but then the &quot;void*&quot;-pointer approach has also one indirection and it has another advantage - you can just put more members in the struct, without any visible change to the clients. So the only overhead i can possibly see is maybe padding of the struct.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="#commentbody-971">
<strong><a href="#comment-971" rel="nofollow">gf</a> :</strong>The only down-side i can think of is the pointer-indirection in high-performance code – but that can get possibly optimized if there is a proven hot-spot there</blockquote>

<p>Hm, but then the &#8220;void*&#8221;-pointer approach has also one indirection and it has another advantage &#8211; you can just put more members in the struct, without any visible change to the clients. So the only overhead i can possibly see is maybe padding of the struct.</p>]]></content:encoded>
	</item>
</channel>
</rss>

