3 ms·
I know basically nothing about the Apple language ecosystem but why does no one ever mention or seemingly use Objective C++? Is it that Objective C is a better
by lloydatkinson 3y ago
I know basically nothing about the Apple language ecosystem but why does no one ever mention or seemingly use Objective C++?
Is it that Objective C is a better version of C with OO and C++ features?
If that’s the case why was Objective C++ created?
- filleokus 3y agoI've always understood Objective C++ to be a way to mix in C++ source code in an Objective-C code base, not really a new language but more of a "mode" of linking / compiling. > Objective-C++ does not add C++ features to Objective-C classes, nor does it add Objective-C features to C++ classes. For example, you cannot use Objective-C syntax to call a C++ object, you cannot add constructors or destructors to an Objective-C object, and you cannot use the keywords this and self interchangeably. The class hierarchies are separate; a C++ class cannot inherit from an Objective-C class, and an Objective-C class cannot inherit from a C++ class. In addition, multi-language exception handling is not supported From a Stack Overflow comment / archived Apple docs: https://stackoverflow.com/a/3684159 https://stackoverflow.com/a/3684159 https://web.archive.org/web/20101203170217/http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCPlusPlus.html https://web.archive.org/web/20101203170217/http://developer....
- jwells89 3y agoYes, in my experience the most common usages are to pair an Objective-C Cocoa UI to cross platform C++ internals, to use C++ for more performance critical parts of an app, or even to just be able to take advantage of the plethora of C++ libraries without going all-in on C++. Things might’ve changed with Swift being around now, but as I understand one place where the Obj-C UI + C++ internals setup used to be common was Audio Unit extensions due to the high latency sensitivity of anything working with audio.
- TillE 3y agoThat first one is probably the most common, you'll see .mm files for Apple-specific platform code in many big cross-platform C++ projects.
- dagmx 3y agoObjective C++ is just a way to mix C++ and Objective C code in the same file. It’s largely a convenience and not its own language so to speak. It’s functionally the equivalent of how you can use C code within C++ code, and a hint to the compiler to allow parsing of C++ syntax as well as ObjC
- saagarjha 3y agoIt sees heavy use, most of it just isn’t public. WebKit is, but for example Facebook uses it for their apps.
- jviotti 3y agoAuthor here. We do a LOT of Objective-C++ at Postman (https://www.postman.com https://www.postman.com), as our upcoming desktop framework is primarily C++.
- olliej 3y agoObjective-c++ is used extensively, it’s just not covered in most discussions of objc because then you’re having to explain the exciting interaction between it objc object semantics and C++’s. Eg the complexity skyrockets. The biggest public user of it would likely be webkit, but plenty of closed software both in and outside of apple use it. But the reality is that it is at this point primarily a bridging language. Post the introduction of ARC one of the biggest win/reason to use it over raw objc went away. But it’s still tremendously valuable as a way to have a nice API that is also ABI stable in a way that isn’t the C and C++ misery pit. Of course now swift has the same ABI stability support as well as a slew of other improvements so there seems ever less reason to write new objc.
- ksherlock 3y agoWhat's there to mention about it? Long ago, c++ exceptions and objective C exceptions didn't play well together but they've been unified so that's not an issue anymore. (In the beginning, Objective c exceptions were macros around setjump()/longjump(). Objective C 2.0 added actual language level support with @try/@catch/@finally/@throw which were compatible with C++ exceptions)
- astrange 3y agoYou shouldn't use Objective-C exceptions though; most code (and by default all ARC code) is not exception safe and will leak memory if you jump through it.
- flohofwoe 3y agoI bet there's a ton of Objective-C++ code around that serves as a shim between a C++ codebase and macOS/iOS system frameworks. The difference to plain ObjC isn't all that big except that the "C part" uses C++ semantics (I guess that's why nobody explicitly mentions it as ObjC++ but just files it under the ObjC umbrella name)
- eschaton 3y agoObjective-C++ was created to enable the creation of the Lotus Improv spreadsheet. The underlying spreadsheet engine was developed in C++ and bridging bidirectional via C to Objective-C for the UI was judged to be too inconvenient, and the developer tools folks at NeXT realized the C++ and Objective-C grammars were easily reconcilable so they put them together to allow mixing at the statement level. It worked great!