Re: [Dev-C++] Error using void main (void)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Robert A. <ral...@gm...> - 2005-04-21 20:06:31
|
Actually, I believe that the ANSI standard allows main to just end without any return code which isn't allowed for any other function declared to return an int. And as a special consideration for main it will return '0' (zero) for you. Actually.. a few web searches indicate that is C++ standard not C. So it looks like for C you are correct... what ever garbage happens to be in the return register. -Robert On 4/21/05, Ray Kulhanek <kul...@wr...> wrote: > 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.) >=20 > 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=3DB4 > > 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 yo= u > >> 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 certai= n > >> 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 >=20 > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=3D6595&alloc_id=3D14396&op=3Dclick > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |