[NTLUG:Discuss] RE: Extremely simple C program...
Fred James
fredjame at concentric.net
Mon Aug 12 10:38:10 CDT 2002
"choose portability over efficiency" - (Unix Philosophy, but just now I
forget the author)
Which would suggest to me that while using "int main()" and "return 0;"
adds a few more keystrokes, it should be the "preferred" form.
To me this inclusion does two important things:
(1) Reminds that main() can return an "exit status" value - a very good
thing
(a) Admittedly I don't very often do so, but it is normally
considered good form to check for the exit status of any program.
(b) I believe (correct me here) that there is an exit status either
way, junk or otherwise, and you may care what it is
(2) Keeps me in the habit of portable standards
(just my 2 cents worth - hope it helps)
Preston wrote:
>Hello,
>
>Originally main was always ment to have return type int. So you could make
>main's return type int and then just add the line: return 0; at the end.
>Most compilers today don't require this. You should just try
>gcc hello.c
>
>then
>
>./a.out
>
>you can also try not including a return type for main at all. Most
>standard, current implementations of gcc will let you get away with this:
>
>#include <stdio.h>
>
>main()
>{
>printf("Hello World!");
>}
>
>Hope this helps. If you decide you really like C, I would recommend getting
>K & R's The C Programming Language. It is a little more pricy than other C
>books, but you can find it for fairly little on half.com or eBay. It was
>written by the guys who wrote C and it is my favorite C book.
>
>Preston
>
>
>_______________________________________________
>http://www.ntlug.org/mailman/listinfo/discuss
>
>
--
small is beautiful
More information about the Discuss
mailing list