views:

71

answers:

2

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! :)

+2  A: 

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.

taskinoor
Yeah no problem, yes, this is my first "major" language. I mean, I know basic HTML and CSS, but they're mainly just markup languages, and jQuery, which is definitely closer to a full programming language. But otherwise, yes this is my first one. I'm also in high school, so I'm picking this up kind of slowly xD
BOSS
Then I will recommend strongly to start from C. As you are already in high school, you have enough time to learn.
taskinoor
OK, I have read before that you do not necessarily have to, but I guess it is better.
BOSS
+1  A: 

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.

Chuck
Yeah, I should have just read the article haha, it explained things pretty clearly.
BOSS