Objective C is a set of backward-compatible extensions to C. This is possible because the Objective C features are delimited in two very simple ways:
- use of the character
@
. This character is not currently used in the C language.
- a simple syntactic extension for invoking methods,
[obj method:argument]
. In C, square brackets are used in a very specific way for array subscripting, and so this is invalid C syntax. Extensions which build on invalid syntax do not change the meaning of anything that is valid in the host language.
So easy to see that no program which uses Objective C extensions can be a strictly conforming ISO C program, no matter how simple. Moreover, every ISO C program can be declared, by definition, to be a valid Objective C program. Objective C can easily follow developments like C99 and C11.
On the other hand, C++ is not simply extensions to C; it is a different language which changes the meaning of some of the syntax of C. C++ and C are separately maintained, and so their relationship changes over time. For instance, C has acquired new features that are completely absent in C++, and quite likely will not go into C++, such as C99 variable-length arrays. C++ cannot easily pick up new C features.
If you write a portable C program, it should be at the same time an Objective C program.
But additional care will be needed so that it is also a C++ program with the same meaning. (This practice is not unheard of, and the dialect it requires is informally known as "Clean C").
A trivial example of a C program that breaks when treated as C++ is any C program which uses a C++ keyword as an identifier, such as class
or virtual
. Objective C does not introduce any reserved keywords. It has new keywords that are introduced by the @
character, like @interface
.