On 30 Jan 2014, at 14:35, Peter Teeson <ptee...@icloud.com> wrote: > The recent flood of language philosophy is informative and interesting but > doesn't address the issues I am interested in. > > My case is one of using the C++ std lib for the containers to work with > traversing a special DAG graph. > I've not found any C or Obj-C code that provides those and I see no reason to > write them myself when C++ has them. > > On 2014-01-29, at 12:13 PM, Abdul Sowayan <asowa...@vectorworks.net> wrote: >>> Are there any current docs that my search didn't find and that you can >>> point me to? >>> Or advice you can offer to help me? >> Well, I’m not clear as to what information you’re trying to find. Can you >> elaborate? >> Abdul > > > In answer to Abdul's question there a a few things that immediately come to > mind: > > The 2005 paper by Josh Anon (I have a pdf) mentions > (0) "The next thing to notice is that we’re mixing #import and #include > directives here. It’s not a problem at all for the compiler. > In fact, we could use: > #import <iostream> > and things would be fine. Actually, using #import is preferable to > #include, > because #import automatically makes sure the file’s only included once > as opposed to having to #ifdef files we #include." > > Still true?
Sure. They both just paste the code into the file. It's just that #import checks whether it already did the file in this compilation unit, #include doesn't. > (1) "Before we begin coding, note that Objective-C++ classes, protocols, and > categories cannot be declared within a separate namespace > (nor can a C++ namespace be declared within an Objective-C++ object) > Everything must be within the global namespace." > > Obviously true - no namespaces in Obj-C. Is that a typo that it says Objective-C*++*? It should say Objective-C classes. C++ classes in ObjC++ can be in namespaces. Objective-C classes in ObjC++ files can't (and clang actually makes that an error, while GCC just ignored the namespace). There is no such thing as an Objective-C++ class. That's one of the main distinctions, both class systems are separate. > (3) "Notice that we’ve intermixed Objective-C’s reference counting memory > management > with C++’s memory management. We cannot call delete on an Objective-C > object, > and we cannot call -release on a C++ variable. > > True even with ARC. Although ARC works on ObjC pointers in ivars of C++ objects. (And since C++ objects are the same as structs to the C++ compiler, they also work on structs under the ObjC++ compiler) > (4) When do we need to use ifdef cplusplus or ifdef objc these days? You use #ifdef __cplusplus when you plan to use C++ code (including those darned extern "C" statements) in headers that get included by C or ObjC source files. You use #ifdef __OBJC__ when you plan to use ObjC code in headers that get included in C++ or C source files. Also keep in mind that you can't just #ifdef out a method in a C++ class that takes an ObjC argument, as that will have the C++ file get a different offset for all following functions than the ObjC++ file. Also, since C++ overloads by type, You can't change the type of an ivar or parameter to a method or function, because then it will get a different name. I go into more detail about all this in the NSBrief podcast, just listen to that. > etc... Too vague :-p -- Uli Kusterer "The Witnesses of TeachText are everywhere..." _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com