Re: ObjC vs C++ (was: Is ZLib available in Cocoa?)
Re: ObjC vs C++ (was: Is ZLib available in Cocoa?)
- Subject: Re: ObjC vs C++ (was: Is ZLib available in Cocoa?)
- From: Scott Ribe <email@hidden>
- Date: Fri, 05 Oct 2007 10:33:28 -0600
- Thread-topic: ObjC vs C++ (was: Is ZLib available in Cocoa?)
I go further; I write extensive new code in C++ for use from Objective-C.
The reasons are complex and almost certainly not relevant to your project,
but there are big chunks of what you would call my "invisible" code where
C++ is a better fit for what I think is the best design.
So, yes it's eminently practical, with only a few gotchas. And the gotchas
can be mostly addressed by a strict separation of functionality between
Objective-C and C++, with tight control over how they interface. In other
words, mostly have the Obj-C user interface call down into the C++, avoid
have call chains going back and forth from one language to the other all
over the place. That said:
- When you embed C++ instances (as opposed to pointers) in Obj-C objects,
constructors & destructors will not be called unless you enable a compiler
option for that, which will only work for 10.3 and up.
- C++ and Obj-C exceptions are not the same, and each language can only
handle its own exceptions. This is the major reason for my advice to limit
the areas where the languages touch. There are, btw some libraries out there
that help with converting exceptions so that they can be thrown across the
"other" language. I don't use them, because in my case it's acceptable to
declare "an uncaught exception is a programmer error: log it, barf, and
die."
For more info:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articl
es/chapter_4_section_10.html>
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden