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

Return code from main ignored #23

Open
paulhankin opened this issue Sep 22, 2021 · 1 comment
Open

Return code from main ignored #23

paulhankin opened this issue Sep 22, 2021 · 1 comment

Comments

@paulhankin
Copy link

The return code from main using libsupcxx is not the same as calling exit, at least in linux-x86_64-libsupcxx . Specifically, sys::exit(1) (which calls the C function exit(1)) causes a shell exit status of 1, whereas "return 1;" from an initial call to main leads to a shell exit status of 0.

Note, the C standard says:
5.1.2.2.3 Program termination

  1. If the return type of the main function is a type compatible with int, a return from the
    initial call to the main function is equivalent to calling the exit function with the value
    returned by the main function as its argument.
@paulhankin
Copy link
Author

paulhankin commented Sep 29, 2021

This is strongly related to #25

My quick look suggests:

  • return n; from main results in an exit status of 0 for all n
  • running off the end of main correctly results in an exit status of 0
  • calling std::exit(n) results in a exit status of 1 for all n (including 0)

I quick look at the code, and a simple test case suggests also that functions registered with std::atexit() are only called if std::exit is not called.

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

1 participant