Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning from main() #496

Open
Scotsgeek opened this issue Jul 5, 2024 · 1 comment
Open

Returning from main() #496

Scotsgeek opened this issue Jul 5, 2024 · 1 comment

Comments

@Scotsgeek
Copy link

Scotsgeek commented Jul 5, 2024

Please check the current issues Many bug reports are duplicates, this just creates more work for us. Searching the issues first may give you your answer or a workaround! If not adding new information to an existing report is much more helpful than a new report.

What Course are you in
Thinkcpp

What Page were you on
5.9 Returning from main

What is your username
None

Describe the bug
"The usual return value from main is 0, which indicates that the program succeeded at whatever it was supposed to do. If something goes wrong, it is common to return -1, or some other value that indicates what kind of error occurred."

Not correct!

The actual value returned to the O/S from main() is actually a 1 byte unsigned value, 0 - 255, even though main() returns an int. So returning -1 from main(), you are actually returning 255!

In stdlib.h, two macros are defined that are commonly used to return from main() or any other function:

"#define EXIT_SUCCESS 0"
"#define EXIT_FAILURE 1"

-1 is used for other purposes such as EOF, or "End Of File", or some other error condition.

See: man EOF

Traceback
None

Javascript Errors
None

@bnmnetp
Copy link
Member

bnmnetp commented Jul 5, 2024

Thanks for the report.

I'd be happy to have someone submit a PR that modifies the wording on the page and makes the fill in the blank accept a variety of answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants