Which dialect of C is Objective-C a "strict superset" of?
I frequently hear that Objective-C is a "strict superset" of the C programming language. There are several dialects/standards of C (ie. K&R, A开发者_开发百科NSI C, C90, C99, GNU extensions...); Objective-C was first developed in the early 1980s, so it has to predate these standards. However, Objective-C 2.0 is from around 2006 or 2007, so it could be based on a more modern C dialect. So, which "C" is Objective-C a superset of?
There's a corresponding "dialect" of Objective-C for all the standard dialects of C.
Given that the most commonly used Objective-C compilers (GCC and Clang) are also C compilers, one would imagine that they support the C dialect(s) supported by these compilers. Apple's documentation specifically states:
The Apple compilers are based on the compilers of the GNU Compiler Collection. Objective-C syntax is a superset of GNU C/C++ syntax, and the Objective-C compiler works for C, C++ and Objective-C source code. The compiler recognizes Objective-C source files by the filename extension .m, just as it recognizes files containing only standard C syntax by filename extension .c. Similarly, the compiler recognizes C++ files that use Objective-C by the extension .mm. Other issues when using Objective-C with C++ are covered in “Using C++ With Objective-C”
So in this case Objective-C is simply regarded as an extension of either the C or C++ compiler depending on which you choose as the base language.
What you're looking for isn't really defined. Objective C is usually thought of a strict superset of ANSI-C (which is the same as C90). However, Objective C isn't a standardized language or anything of that sort. It's description basically is "Take C, and add these features to it". It's therefore dependent on the particular compiler you're using.
According to "Learning Objective-C" from Apple:
"Objective-C is a superset of the ANSI version of the C programming language and supports the same basic syntax as C."
精彩评论