What does "Objective-C is a superset of C more strictly than C++" mean exactly? What does "Objective-C is a superset of C more strictly than C++" mean exactly? objective-c objective-c

What does "Objective-C is a superset of C more strictly than C++" mean exactly?


I prepared a simple diagram; it is not very pretty, but hopefully gets the point across:

  • Red: the set of all programs valid in C, C++, and Objective-C (relatively small)
  • Green: the set of all programs valid in C and Objective-C, but invalid in C++ (even smaller)
  • Gray: the set of all programs valid in Objective C and C++, but invalid in C (empty, as far as I know)
  • Blue: the set of all programs valid only in Objective C (relatively large)
  • Yellow: the set of all programs valid only in C++ (largest)

The set of valid C programs (in red and green) is an strict subset of the set of valid Objective C programs (blue)

enter image description here


  1. 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.

  2. 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.

  3. In what way does objective-C follow the C philosophy more closely than C++?

    All - Objective-C is a strict superset of C.

  4. 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 enums 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.