tags:

views:

84

answers:

2

What is the use of returning an integer for main in Objective-C programs.

+10  A: 

I assume the same as in C programs. Return value is useful when you run application from command line it gives you indication if it failed or not.

Most commands in shell give indication like that. You can then build shell script and run your app, check return value and do something based on that.

C was originally created for writing operating systems like Unix.

For example take some linux/unix utility like ls command:

> ls
bla1 bla2
> echo $?
0
> ls bla3
/bin/ls: bla3: No such file or directory
> echo $?
1

Now you can use the return value in shell script.

stefanB
That's a new knowledge to me...Thanks stefanB
Sumit M Asok
Even better than referencing $?, you can simply write: if ! ls dir; then ...; fi
William Pursell
Yes that's how it would be used in scripts, I just wanted to show that there's a value returned by even something like `ls` ...
stefanB
A: 

As Stefan assumes, Cocoa apps return an integer from main() because they follow the UNIX conventions. In practice, we rarely return anything other than zero unless the app has crashed.

NSResponder