views:

258

answers:

5

As the title says... are they considered different languages? For example if you've written an application using a combination of C++ and Objective-C++ would you consider it to have been written in C++ and Objective-C, C++ and Objective-C++ or all three?

Obviously C and C++ are different languages even though C++ and C are directly compatible, how is the situation with Objective-C++ and Objective-C?

+6  A: 

From: http://en.wikipedia.org/wiki/Objective-C#Objective-C.2B.2B

Objective-C++ is a front-end to the GNU Compiler Collection, which can compile source files which use a combination of C++ and Objective-C syntax. Objective-C++ adds to C++ the extensions Objective-C adds to C. As nothing is done to unify the semantics behind the various language features, certain restrictions apply:

  • A C++ class cannot derive from an Objective-C class and vice versa.
  • C++ namespaces cannot be declared inside an Objective-C declaration.
  • Objective-C classes cannot have instance variables of C++ classes which do not have a default constructor or which have one or more virtual methods, but pointers to C++ objects can be used as instance variables without restriction (allocate them with new in the -init method).
  • C++ "by value" semantics cannot be applied to Objective-C objects, which are only accessible through pointers.
  • An Objective-C declaration cannot be within a C++ template declaration and vice versa. However, Objective-C types, (e.g., Classname *) can be used as C++ template parameters. Objective-C and C++ exception handling is distinct; the handlers of each cannot handle exceptions of the other type.
  • Care must be taken since the destructor calling conventions of Objective-C and C++’s exception run-time models do not match (i.e., a C++ destructor will not be called when an Objective-C exception exits the C++ object’s scope). The new 64-bit runtime resolves this by introducing interoperability with C++ exceptions in this sense
ItzWarty
That first point is not strictly true. I made a C++ class that derived from NSObject.
drawnonward
I already read the Wikipedia article but it didn't really tell me what I was looking for...Also, @drawnonward, are you sure? Seems a bit unlikely that Wikipedia would be wrong on such a major point.
Jake Petroules
+2  A: 

C and C++ are not directly compatible. Neither is a superset of the other (though most C is valid C++). Objective-C is a strict superset of C, and Objective-C++ is a strict superset of C++. Those are the only statements you can make (except trivially reversing it).

Matthew Flaschen
+1  A: 

It's hard to answer this question confidently without understanding what definition of "different language" you want to apply.

Objective-C is a superset of C: it adds some additional syntax on top of the C language. Objective-C++ is a superset of C++ in the same way.

C and C++ are actually different languages. Although C++ is designed to be compatible, there is some C that is not valid C++, and vice versa.

So, I'd say, yes, Objective-C++ is a different language from Objective-C, because C++ is a different language from C. However, I wouldn't call them totally different.

benzado
+3  A: 

Objective-C++ simply allows Objective-C and C++ code to be mixed (with caveats). It's not really a language on its own so much as a mechanism for allowing the two languages to intermix.

Michael Aaron Safyan
I'm accepting this answer as it was worded in the most accurate way, in my opinion. This makes perfect sense and I believe I understand what Objective-C++ really is now. Thank you.
Jake Petroules
+1  A: 

Objective-C is probably the official term that you would put in a resume.

Objective-C++ is not really a new language, it just specifies a few things that allow Objective-C code to co-exist with C++ code. Saying your app was written in Objective-C and C++ or just Objective-C++ is probably what you want. Putting all of Objective-C, Objective-C++, C++ is redundant.

5ound
Second best answer, thanks.
Jake Petroules