• Advertisement

Archived

This topic is now archived and is closed to further replies.

c++

This topic is 5496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Just an hint: nobody is going to understand your question if you don''t clarify it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here is the c++ program you requested:

int main(void)
{
return 0;
}

Enjoy.

Share this post


Link to post
Share on other sites
Ummm. First, C++ is not a program, it's a language. You use the C++ langauge in addition to some other tools to make programs. Second, I'm assuming you want/need a compiler, which is a tool to convert your code into machine langauge (binary). There are several compilers out there. You didn't specify an OS, but...
Windows:
Microsoft Visual C++
Borland Compiler Turbo?
DGJPP <-- Free
DevC ?

Linux <- There are some compilers that come with the OS
Maybe someone could list some. I've had very little experience with Linux (non-programming)

Mac OS:
Apple bundles a compiler with their OS called Project Builder
and Also a compiler called CodeWarrior from another company.

Third you probably want a book. I can't recommend what the best C++ programming book is, because I don't have any that would qualify. Well there is one, but it's more of a reference.

I have:
Learn C++ in 24 Hours <-- DO NOT BELIEVE THE TITLE
C++ for Dummies <--- DO NOT TAKE THE TITLE SERIOUSLY
C++ The Complete Reference 3rd Edition <-- A book for people with C++ experience

Theres a college C++ book from Deitel and Deitel. Can't remember the name though. It's pretty good.


I don't have a signature

[edited by - Brian Jones on February 6, 2003 9:49:03 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
Here is the c++ program you requested:

int main(void)
{
return 0;
}

Enjoy.

I think this is better though:

int main()
{
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Anonymous Poster

I think this is better though:

int main()
{
}



Why because it won''t compile?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
Here is the c++ program you requested:

int main(void)
{
return 0;
}

Enjoy.


But we might aswell help him out with standard C++ if we''re going to give him examples.

Main does NOT take void as an argument and it doesn''t HAVE to return anything.

Cheers.

Share this post


Link to post
Share on other sites
if you declare

int main()
{
}

it HAS to return an int, because you are saying it will!!!

int <-return type main <-Function name ()<- Parameters



void main()
{
}

is correct though, because you are saying we are returning nothing!

Share this post


Link to post
Share on other sites
Hello,

This could lead to one of the most interesting discussions in a long time. Who want:
int main()
{
return 0;
}

who wants:
int main()
{
}

and who wants:
void main()
{
}


Regards,
Deficte

Share this post


Link to post
Share on other sites
Depends what you want to do.
If your main does not return, then

void main()
{
} is good.

I prefer
int main()
{
return 0;
}
because I want 0 return.

int main()
{
}

unfortunately will not compile, because you arent returning anything.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

But we might aswell help him out with standard C++ if we're going to give him examples.

Main does NOT take void as an argument and it doesn't HAVE to return anything.

Cheers.



Wrong! The C standart says that main _must_ return an int.
Nevertheless most compilers will accept "void main"

[edited by - noVum on February 7, 2003 7:06:37 AM]

Share this post


Link to post
Share on other sites
Not only does the standard say that main must return an int but it also says that falling off the end of main implies a return of 0. So,

int main()
{
}

is the exact same thing as
int main()
{
return 0;
}

It is simply a matter of style whether you want to type the return statement or not.

Share this post


Link to post
Share on other sites
Why does a thread about helping someone start C++ end in a discussion whether main() is required to return an int?

I don''t have a signature

Share this post


Link to post
Share on other sites
MSVC just doesn''t handle this correctly, so for MSVC, either "return 0" manually or use the void declaration (which goes against the standard but works nonetheless)

Share this post


Link to post
Share on other sites
Straight from the standard:

quote:
An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined.


So the arguments to main are arbitrary, although the standard requires that both

int main();
int main(int argc, char * argv[]);

be allowed. The standard also states:

quote:
A program shall contain a global function called main, which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main function.


Which by my understaning allows for nonstandard entry points like WinMain.

Share this post


Link to post
Share on other sites
quote:
Original post by Brian Jones
Why does a thread about helping someone start C++ end in a discussion whether main() is required to return an int?
The communist GameDev has always been like this


return 0;

Share this post


Link to post
Share on other sites
quote:

int main(){}


Build: 1 succeeded, 0 failed, 0 skipped
Compile Success
MSVS.net

Share this post


Link to post
Share on other sites
The C++ standard requires that compilers allow the main function to be declared as int, and requires that they allow a main function with a void or int,char** argument list. However, all compilers I know of allow (with warnings) a main function to return void, or to fall off the end of the int main function without returning a value. In such cases, 0 is returned.

And that''s all I have to say about that.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
The college ref book for C++ from Deitel and Deitel is called C++ How to Program. I have the C version and it is an excellent book to learn how to program. I love it if I could ever find it again...it got misplaced when I moved. Great book for reference and/or to teach you the language.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

But we might aswell help him out with standard C++ if we''re going to give him examples.

Main does NOT take void as an argument and it doesn''t HAVE to return anything.

Cheers.


Oops. Looked like I hijacked this thread with my ambiguous post above. What I intended to say was that:-

1) main doesn''t take void as an argument

2) it doesn''t have to return anything. i.e. it is a special function in the sense that you don''t need to return an integer. If control reaches the end of main without finding a return statement it will have the same effect as return 0;

3) and I''ll add another point - main must have a return type of type int.

This post to comp.lang.c++ says it well

Happy C++ing

Share this post


Link to post
Share on other sites

  • Advertisement