4 ms·
It should work for g++, as long as you build you own "std" module (which sadly is somewhat complicated) and enables -fmodule-ts. I guess he's hoping that will
by nn3 4y ago
It should work for g++, as long as you build you own "std" module (which sadly is
somewhat complicated) and enables -fmodule-ts. I guess he's hoping that will be easier in 2023.
What bothers me more is the lack of "return 0"
- garaetjjte 4y agoOmitting return is allowed in main.
- nn3 4y agoOn 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.
- matthews2 4y agoThere's an implicit return zero in C++.
- pjmlp 4y agoIn C yes, on C++ it is required to return 0 if omited.
- garaetjjte 4y agoC99 also defines it: >5.1.2.2.3 Program termination [...] reaching the } that terminates the main function returns a value of 0.
- pjmlp 4y agoThanks for the heads up, than it sums it up either the OP was using a broken implementation, or the incorrect language version.
- Jtsummers 4y agoIt 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.
- shawn-butler 4y agoC++ standard 3.6.2[5] since like forever... A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;