[Coco] Re: Preparing for a job which requires knowledge of C

Mark McDougall msmcdoug at iinet.net.au
Sun Apr 16 03:42:34 EDT 2006


doctorx0079 wrote:

> In a C program, the main() function has a return value of void. In other
> words, it doesn't return any value.
> In a C++ program, the main() function has a return value of int. In other
> words, it must return an integer.

No, not right. See the C99 standard.

Also, from faq.cprogramming.com...

---8<------8<------8<------8<------8<------8<------8<------8<------8<------8<---

What's the deal with void main()

Under regular function calling/returning in C and C++, if your don't ever 
want to return anything from a function, you define it's return type as 
void. For example, a function that takes no arguments, and returns nothing 
can be prototyped as:

void foo(void);

A common misconception is that the same logic can be applied to main(). 
Well, it can't, main() is special, you should always follow the standard and 
define the return type as int. There are some exceptions where void main() 
is allowed, but these are on specialised systems only. If you're not sure if 
you're using one of these specialised systems or not, then the answer is 
simply no, you're not. If you were, you'd know it.

---8<------8<------8<------8<------8<------8<------8<------8<------8<------8<---

Regards,

-- 
|              Mark McDougall                | "Electrical Engineers do it
|  <http://members.iinet.net.au/~msmcdoug>   |   with less resistance!"



More information about the Coco mailing list