I noticed "Avoid void main()" tip in tip page has a hard time earning good points. Tell me, who didn't vote 5 for that - why is void main() good?
Printable View
I noticed "Avoid void main()" tip in tip page has a hard time earning good points. Tell me, who didn't vote 5 for that - why is void main() good?
Where is this page?
Could it be this one? I suppose one might give it a low rating due to lack of elaboration, since it basically shifts the work to an external website.
Tips can be found at the www.cprogramming.com page, along the left.
void main() might work for you but that shouldn't matter. main() always returns an int. Thread over.
Thanks.
Anyways, that and probably the fact that it's beating on a dead horse.
Dead horse - you mean noone really is using void main()?
I am frustrated to see tons of examples in the net which use void main().
I tend to shake my head and sigh rather than get frustrated.Quote:
I am frustrated to see tons of examples in the net which use void main().
Dead horse in the sense this issue has been beaten to death.Quote:
Originally Posted by maxorator
Look, see it this way...
That's not a tip. It's a language feature assessment. I would give it a 0 rating. I could write a tip to tell people not to use a return statement inside a function that returns void. Some compilers issue a warning. Others don't even bother. Probably only a handful (if any) make that an error even with -pedantic on. However, I would really be just stating the obvious. As with the void main() thing.
A tip should answer the "how", really.
How not to use void main? I'd rather the why than the how.
The why is answered on the standards, programming books and articles.
The compilers I use return an int regardless of how you declare main(). For example in the code below the compiler will return a pointer to the text as an integer. Of course that integer pointer is useless outside the program but it works anyway.
Code:char* main()
{
return "Hello";
}
MinGW returns an error (hurray!) on T main() even without -Wall, -Wextra and -pedantic when T is not int.
The T made me try a function template:Quote:
MinGW returns an error (hurray!) on T main() even without -Wall, -Wextra and -pedantic when T is not int.
But of course it didnt work, Comeau C++ reports that "main" is not a valid name for a function template. Silly me.Code:template <typename T>
T main()
{
return T();
}
main<int>();