Re: [Dev-C++] Error using void main (void)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Ray K. <kul...@wr...> - 2005-04-21 18:20:35
|
Another thing to consider is that, as far as I know, while the return *type* of a function defaults to int, the return *value* doesn't default to anything in particular. If so, it might just return whatever value happens to live in memory at a certain point, and if the value is anything other than 0, the operating system will interpret that to mean that the program terminated with an error. (It's good form to include the type specification and return statement, regardless.) Per Westermark <pw...@ia...> wrote: > Note that > main() > is ONLY allowed for C programs, where a symbol without a declared data > type defaults to int, i.e. > main() > in reality means: > int main() > in a C program. > For C++ programs, you MUST actually use > int main() > since the ISO C++ standard requires it. Yes, I know that g++ do accept > the > lazy form and only emits "warning: ISO C++ forbids declaration of > `main=B4 > with no type" if warnings are enabled. However, don't assume something > about how other compilers look at ISO compliance requirements! > /Per W > On Thu, 21 Apr 2005, Austin Scholze wrote: > >> also, I have found in dev-C++ that you may just use >> >> main() >> >> without actually initializing it and that it will exit at the end of >> the function. >> ----- Original Message ----- >> From: Verne H. Bohlender >> To: Dev C++ ; Alfred P. Reaud >> Sent: Wednesday, April 20, 2005 9:48 PM >> Subject: Re: [Dev-C++] Error using void main (void) >> >> >> That's what it should say as it really should be >> >> int main() or with all the other goodies inside the brackets. If you >> read across it says"int main void for the two ( )'s for the void here! >> >> Verne >> The GRIN Genius who knows nothing! >> >> Warnings are mostly ignorable, or nice if you like to write clean >> portable code. main should always return an int as that's the exit >> value that the executable gives to DOS/Win/Linux upon completion. >> Source should compile and run with a void main. However, main's exit >> value will then always be 0 and therefore useless to test for a certain >> execution completion status. >> >> Alexsandro Meireles <mei...@gm...> wrote: >> Hi, all! >> >> I tried to use the following expression in Dev-C++ >> >> void main (void) >> >> The compiler give a warning message "output of main is not int". >> Something like that. Although it gives this warning it compilies well. >> Why this happens? Main should always have a return type? >> >> Tks in advance! >> >> -- >> Alexsandro Meireles >> >> >> >> Alfred P. Reaud |