Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

objective-c

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.

like image 721
user1115057 Avatar asked Oct 14 '13 17:10

user1115057


People also ask

Is Objective-C superset of C?

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.

What is the difference between Objective-C and C?

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.

What is superset C?

C++ is a superset of C. All your C programs will work without any modification in this environment.

Why the C Plus Plus is superset of C?

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.


3 Answers

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

like image 126
Escualo Avatar answered Oct 16 '22 23:10

Escualo


  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.

like image 63
Carl Norum Avatar answered Oct 17 '22 00:10

Carl Norum


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.

like image 32
Sergey Kalinichenko Avatar answered Oct 16 '22 23:10

Sergey Kalinichenko