From what i read there: Why is Objective-C not very popular outside of the Apple community?
Objective-C is a superset of C (much more strictly than C++, in fact) so the issue of backward compatibility does not arise. Anything you can do in C you can do in Objective-C.
Being a superset is binary, like being pregnant. Obj-C is a superset of C, and C++ is not.
What do they mean by superset? In what way does objective-C would be more close//backward compatible to C? In what way does objective-C follow the C philosophy more closely than C++?
Can any C program be compiled without modification by a objective-C compiler (100% compatibility)?
This is more a question about programming language design and compatibility than a wars about which one is better.
Objective-C is a thin layer atop C and is a "strict superset" of C, meaning that it is possible to compile any C program with an Objective-C compiler and to freely include C language code within an Objective-C class. Objective-C derives its object syntax from Smalltalk.
The main difference in C and Objective C is that C is a procedure programming language which doesn't support the concepts of objects and classes and Objective C is Object-oriented language which contains the concept of both procedural and object-oriented programming languages.
C++ is a superset of C. All your C programs will work without any modification in this environment.
Answer. Answer: When he designed C++, he added OOP (Object Oriented Programming) features to C without significantly changing the C component. Thus C++ is a "relative" (called a superset) of C, meaning that any valid C program is also a valid C++ program.
I prepared a simple diagram; it is not very pretty, but hopefully gets the point across:
The set of valid C programs (in red and green) is an strict subset of the set of valid Objective C programs (blue)
What do they mean by superset?
They mean strict superset. Any valid C program will compile with an Objective-C compiler. Some valid C programs will not compile with a C++ compiler.
In what way does objective-C would be more close//backward compatible to C?
Here's a simple example:
int *foo = malloc(12);
Compiles in C and Objective-C, but not in C++. There are, of course, other examples as well.
In what way does objective-C follow the C philosophy more closely than C++?
All - Objective-C is a strict superset of C.
Can any C program be compiled without modification by a objective-C compiler (100% compatibility)?
Yes.
From the ground up, C++ has been designed as a "better C", fixing design omissions, both real and perceived, as the authors of C++ went through the language. The result of this design decision has been that X
being a valid C program did not guarantee that X
would compile, let alone run, when processed by the C++ compiler. The changes touched such basic constructs as string literals (they became const char*
), assignment of void
pointers, conversions between enum
s and integral types, semantics of compound assignment operators, and so on.
Moreover, once C99 came along, features that made it into the updated C standard were left out from the updated C++ standard. Again, very important language features were left out - most notably, designated initializers and variable-size arrays.
In contrast, Objective C has been positioned as a superset of C, requiring all valid C programs to be compilable with an Objective C compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With