News for hackers. Stuff that matters.
Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by garaetjjte on Sunday October 30, 2022 @10:05AM (#33394607)
Omitting return is allowed in main.
Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by nn3 on Sunday October 30, 2022 @10:07AM (#33394624)
On Linux/Unix you will get in a (somewhat) random exit value, so if you run the program from a "set -e" script it will randomly fail. I guess that didn't bother whoever "allowed" that, but I consider it a bug.
Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by Jtsummers on Sunday October 30, 2022 @10:18AM (#33394699)
It shouldn't in C++. Omitting an explicit return (or falling through to the end without hitting another return) should have the same result as if you ended it with `return 0`. If it's returning a random value then that is erroneous behavior. I've also never witnessed this and print non-zero exit codes in my command line prompt (so after execution my prompt looks like `blahblah(EXIT_CODE) $`).

And I just looked it up for C. Since C99, if the return type of `main` is `int` and there is no explicit return (or again you fall through to the end without hitting one) there's an implicit `return 0`. Before C99, undefined.

Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by matthews2 on Sunday October 30, 2022 @10:16AM (#33394689)
There's an implicit return zero in C++.
Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by pjmlp on Sunday October 30, 2022 @10:15AM (#33394684)
In C yes, on C++ it is required to return 0 if omited.
Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by garaetjjte on Sunday October 30, 2022 @10:25AM (#33394744)
C99 also defines it:

>5.1.2.2.3 Program termination [...] reaching the } that terminates the main function returns a value of 0.

Re:A Tour of C++, 3rd edition (covering C++20 plus a few lik... by pjmlp on Sunday October 30, 2022 @11:31AM (#33395294)
Thanks for the heads up, than it sums it up either the OP was using a broken implementation, or the incorrect language version.