Reputation: 19163
Hey, I was wondering how Objective-C function declarations worked, and why I would want to declare another function besides main.
For example, I now that, at least from most programs I have been exposed to, Objective-C programs begin execution at the function named main, and the name main is therefore reserved.
Now, the reason we usually "return 0" at the end is to show that everything went normal, correct? And, because we specified main would be a function of type "int", or integer.
I was wondering how common it is, I guess it depends on the scale of the program however, to declare other functions besides main, and how I should do so.
UPDATE:
Actually, sorry, I found a pretty good guide right here: http://www.techotopia.com/index.php/An_Overview_of_Objective-C_Functions
But additions are certainty appreciated! :)
Upvotes: 1
Views: 466
Reputation: 46027
Please don't mind for my question. Is Obj-C the first language that you are learning? I'm asking this as most of the things that you have asked is about general concepts of programming. About the main function or returning int, these all came from C. Remember, Obj-C is superset of C language. If you don't know C / C++, then I would recommend you to look at them before jumping to Obj-C. The reason is there are hundreds of C / C++ resources for the beginners. But I'm afraid there are not much on Obj-C for the beginners. For example, there is little possibility that an Obj-C text will explain in detail what a pointer is, what is dynamically allocated memory, what is recursive function, what is the role of object, what is static member etc.
May be I'm wrong. May be there are some texts on Obj-C for the beginners. Personally I have not searched one as this was not my first language.
Upvotes: 2
Reputation: 237010
You want to declare functions besides main()
because a packing even a relatively small 5000-line program into main()
would be completely insane. It would also contain lots of duplicated code since you aren't factoring common operations into functions.
Upvotes: 1