is it by any means not recommended to use 'void main' even if your program is not returning anything...heard ppl sayin go for 'int main' & put 'return 0' in the end if aint got nethng to return....why so???
is it by any means not recommended to use 'void main' even if your program is not returning anything...heard ppl sayin go for 'int main' & put 'return 0' in the end if aint got nethng to return....why so???
Read the FAQ. Or search the forum.
Quzah.
Hope is the first step on the road to disappointment.
got the answer at http://users.aber.ac.uk/auj/voidmain.shtml
but didnt get this paragraph:
"Because the startup routines that call main could be assuming that the return value will be pushed onto the stack. If main() does not do this, then this could lead to stack corruption in the program's exit sequence, and cause it to crash."
Pretty much what it says.
The startup routine (not you) call main.
Therefore, you should really write a function with the prototype they expect to call, not some half-baked lazy approximation.
I mean, if you think void is acceptable, what about this?
I mean, there's no difference between being a little bit wrong and being a lot wrong is there?Code:#include <stdio.h> struct dumb { int a[10000]; }; struct dumb main ( void ) { struct dumb result; printf( "hello world\n" ); return result; } $ gcc -Wall -W -ansi -pedantic hello.c hello.c:3: warning: return type of `main' is not `int' $ ./a.out hello world Segmentation fault
> in the end if aint got nethng to return
Well if simply adding "return 0;" is too difficult for you, try something else.
I mean, it's nothing compared to the 1000's of lines which go into any decent sized program.
Tell me, for functions you write, do you happily abuse the calling conventions of those functions as well?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.