Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Visual Studio Help

Reply
Thread Tools

Visual Studio Help

 
 
Thomas Matthews
Guest
Posts: n/a
 
      07-30-2003
Goonigooguu wrote:
> Thanks all. Bloodsheds Dev-C++ works just fine but I do have other question.
> Usually is start my main() as follows without a return:

1. Don't top-post. Replies are either interspersed or appended
at the bottom.

> void main()
> {
> //code body
> }
>
> This causes a problem with Dev-C++ and I have to use:
> int main()
> {
> //code body
> system("PAUSE")
> return 0;
> }
>
> Is this a problem or normal. Please explain in laymans terms. Thanks.

As stated many times in this newsgroup and news:comp.lang.c,
the main() function returns an int. Always. No exception.
Anything else provokes undefined behavior. As to what normal
is, that is a misleading term.

The correct form for a minimalist C++ program is:
int main()
{
}

According to the standard, the main() function is the only
function that has a default return value. Constructors
are special functions that don't return values. Better
form for the main function is:
int main(void) // or (int, char **)
{
return EXIT_SUCCESS; // or EXIT_FAILURE
}

Read the FAQ and welcome.txt via the links below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      07-30-2003
Thomas Matthews wrote:

>The correct form for a minimalist C++ program is:
>int main()
>{
>}
>
>According to the standard, the main() function is the only
>function that has a default return value. Constructors
>are special functions that don't return values. Better
>form for the main function is:
>int main(void) // or (int, char **)


The practice of using a 'void' argument list is meaningful in
C (do you know _why_ it is meaningful in C?).

It's not meaningful in C++.

It's not a good idea to use meaningless constructs, and so
this form is absolutely not "better" in C++: it is inferior.



>{
> return EXIT_SUCCESS; // or EXIT_FAILURE
>}


This can be a good idea. Note: EXIT_SUCCESS is not predefined
in C++. It is defined by various header files.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is Visual Studio 2005 complict with Visual Studio 2003 rockdale ASP .Net 1 08-23-2006 07:20 PM
Should I write Visual studio 2005 or Visual studio 2003 MCSD =?Utf-8?B?VmlqYXk=?= Microsoft Certification 14 06-30-2006 09:05 AM
Is Visual Studio Team System and Visual Studio Foundation Server are same?. Thirumalai ASP .Net 0 05-22-2006 08:48 AM
visual studio .net 2003 verses visual studio .net 2002 wh ASP .Net 2 01-16-2004 04:54 PM



Advertisments