Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning C for Objective-C

Tags:

c

objective-c

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?

like image 970
pasawaya Avatar asked Jun 02 '12 00:06

pasawaya


People also ask

Should I learn C before Objective-C?

Absolutely – you can learn Objective-C without knowing C. And in fact, if you're interested in learning to build iOS apps, you should just learn Objective-C first – it'll get you there much more quickly than learning C first, then Objective-C, then the iOS frameworks…

Is Objective-C compatible with C?

Objective-C is an object-oriented programming language that is a superset of C, as the name of the language might reveal. This means that any valid C program will compile with an Objective-C compiler. It derives all its non-object oriented syntax from C and its object oriented syntax from SmallTalk.

Is Objective-C difficult to learn?

Aside from its funny-looking syntax, Objective-C is an easier language for beginner developers to learn.

Is Objective-C same as C?

Syntactically, Objective-C is an extension of C. So, some portion of Objective-C is exactly the same as C. Your experience of C would help learning such aspect of Objective-C. But the core part of Objective-C programming is made of Object Oriented class system, which you cannot find in C.


2 Answers

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)

like image 128
Stefan Avatar answered Sep 18 '22 02:09

Stefan


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

like image 42
steveha Avatar answered Sep 20 '22 02:09

steveha