I am relatively proficient in Objective-C but I have been looking around some frameworks and libraries I might use in the future and I am increasingly seeing the use of C. So far the only applications I have written contain only Objective-C. I know Objective-C is a superset of C, but what I mean when I say that I have only written in Objective-C is that I have only used Objective-C methods and the syntax of Objective-C that is distinctly different from C syntax. I've been going through questions related to the relationship between C and Objective-C (see links below) and I want to start learning C, but apparently there are three types of C (K&R, C89, and C99), and I am wondering which type I should learn to help me with Objective-C. I know from learning Objective-C I unknowingly learned C too, but I want to understand the ins and outs of C more and become familiar with its functions, syntax, features, etc. Also, is Objective-C based off of any one of the three types of C?
-
I'm not asking for books. I'm asking for which type of C (K&R, C89, C99) to learn. – pasawaya Jun 02 '12 at 00:30
-
1As I mentioned in my answer below, Objective-C in its current form is based on C99 (minus floating point pragmas, actually). – Stefan Jun 02 '12 at 00:40
-
No problem... Added some more info... – Stefan Jun 02 '12 at 00:44
2 Answers
I suggest you look at some introductory texts on C, and learn whatever C dialect the text teaches. This will likely be C89 or C99.
K&R C is missing modern features such as "prototypes" (declaring the number and types of arguments to your functions). C89 adds all that stuff in.
C99 has, mostly, small incremental features that are useful in specific domains. The bulk of the stuff you need to learn should be identical across C89 and C99. Fun fact: Microsoft never bothered to implement C99.
Actually, I will suggest a specific introductory text: use the Second Edition of K&R. This basically updates K&R to C89. K&R is an outstanding book, and a great choice for learning the C language.
https://stackoverflow.com/questions/1646667/kr-1st-edition-vs-2nd-edition
-
Fun fact: there's no good reason to implement C99 fully when the respective C++ standard (C++98 IIRC) implements most of the desperately wanted features of C99 and adds extra type safety while only leaving out the minor stuff that is not compatible between C and C++ ... ;) ... Microsoft saw it this way and I agree. Besides, single-line comments are implemented even in MSVC, aren't they? Well they aren't in C89 ... what now? Still +1 – 0xC0000022L Jun 02 '12 at 00:51
-
1I am very surprised to see you defending Microsoft on this point. Many of the new features of C99 were already implemented by Microsoft, using their own proprietary versions, by the time C99 was standardized, so many of the C99 features are just a #ifdef away. And sure they added one-line comments. But the fact remains that there is a lot of cool stuff that they didn't implement, and those of us who still work in C would like them. The one that I really care about is designated initializers for unions (NOT available in C++ either): http://stackoverflow.com/a/856026/166949 – steveha Jun 02 '12 at 02:03
-
2@0xC0000022L: Even C++11 still doesn't have some of the more useful features of C99; C++ is in no way a replacement for current C support. – Stephen Canon Sep 24 '12 at 22:05
-
@Stephen Canon: please name some. Also, I wasn't discussing C++11 vs. C99. I reckon more people should read the Stroustrup article "Sibling Rivalry" and think and work toward a richer and harmonized C/C++ "biosphere". Bashing single vendors won't help. Even some of the GCC limitations/extensions aren't exactly helpful when you have to use five different compilers on more than a dozen platform/architecture pairs in various incarnations (i.e. different compiler versions). SunC freaks me out with lacking support for anonymous unions, for example ... so what? I'm a developer. I work around issues. – 0xC0000022L Sep 25 '12 at 07:01
There are even more types of C. In the meantime C0X and C11 were defined... They all make only small evolutionary steps from their predecessors, so you shouldn't worry much about it. Objective-C is based on C99 (minus floating point pragmas, actually), so for now that would probably be the best fit.
It's not entirely clear from your question, but you do notice that those variations of C are just evolving specifications from different years? K&R from ca. 1978, C89 from 1989, C99 from 1999 etc... Objective-C was designed to be a strict superset of C, so you can probably expect Objective-C to incorporate C11 features some day.
(NB: several edits to include information from the comments)

- 1,347
- 2
- 16
- 38
-
MSVC for example has a mix between a few C99 features and C89/C90. Other compilers require you to enable explicitly C99 support, so I'd recommend C89 as the common denominator that is virtually supported everywhere. – 0xC0000022L Jun 02 '12 at 00:48
-
So will Objective-C update periodically to incorporate the latest version of C? – pasawaya Jun 02 '12 at 00:51
-
2Since Apple currently is the driving force behind Objective-C, only they can tell for sure. Objective-C was designed to be a strict superset of C, so I assume they will want to stay up to date. – Stefan Jun 02 '12 at 00:58
-
2