943,600 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1708
  • C++ RSS
Feb 16th, 2008
0

void main() and int main()

Expand Post »
is there any advantage in using int main() over void main()?.
and when you return a value in int main(), where does the returned value go?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mario123 is offline Offline
2 posts
since Jan 2008
Feb 16th, 2008
1

Re: void main() and int main()

> is there any advantage in using int main() over void main()?.
Quote ...
The definition void main() { /* ... */ } is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ } and
int main(int argc, char* argv[]) { /* ... */ } A conforming implementation may provide more versions of main(), but they must all have return type int.
-- Stroustrup

> when you return a value in int main(), where does the returned value go?
Quote ...
The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
-- Stroustrup
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Feb 16th, 2008
0

Re: void main() and int main()

Link with FAQs and other information
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Feb 16th, 2008
0

Re: void main() and int main()

Is the advice different for devices that do not necessarily have an operating system.

Like embedded devices though?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 16th, 2008
1

Re: void main() and int main()

SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Feb 16th, 2008
0

Re: void main() and int main()

Click to Expand / Collapse  Quote originally posted by iamthwee ...
Is the advice different for devices that do not necessarily have an operating system.

Like embedded devices though?
Yes it would be different -- programs written for embedded devices without operating systems don't call exit() or return from main() because there is no place to return to. Embedded programming has a different set of standards then other ISO standards.
Last edited by Ancient Dragon; Feb 16th, 2008 at 10:00 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Feb 16th, 2008
0

Re: void main() and int main()

>Is the advice different for devices that do not necessarily have an operating system.
Freestanding implementations are excepted from a lot of the rules of hosted implementations. But since a programmer on a freestanding implementation is highly unlikely to be asking this question, and int main is always correct, the advice stands.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Array/ Recursive Problem
Next Thread in C++ Forum Timeline: c++ Hardware





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC