[Courses] Absolute Beginning C: void?
Mel Chua
mel at melchua.com
Mon Feb 6 05:47:07 UTC 2012
Aaaaaand I just read Akkana's message, so that first technical question
will be now, in fact. :D
> For little programs like this, there's no need to bother with
> returning error codes, so you're going to pretend that main() doesn't
> return anything, and so it actually is good coding practice to say
>
> void main()
I just tried these three things out:
0) Running the original program with the -Wall option to make sure I got
the same error message that Akkana described. (I did.)
1) changing the 2nd line to 'int main()' and adding 'return 0;' at the
end of the main() function. (This worked perfectly, no error
messages/warnings whatsoever, awesome.)
2) changing the 2nd line to 'void main()' (with no 'return' statement at
the end of the main () function). (This resulted in a warning:
'welcome.c:2:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]')
So it looks like gcc doesn't like it when main() is told to return
another type of value -- is there any particular reason why, and is this
something unique to the main() function?
--Mel, who's was taught C in the school of "kludge 'till it works well
enough for competition/demo because we won't have to maintain/extend it
afterwards" by a bunch of other high school and college kids, which
unfortunately explains a lot of my coding style/abilities.
More information about the Courses
mailing list