4 ms·
> if just for the reason that no accidential implementation-defined behaviour sneaks into the specification How's this going for languages with multiple compil
by ddek 5y ago
> if just for the reason that no accidential implementation-defined behaviour sneaks into the specification
How's this going for languages with multiple compilers, such as C++?
- qalmakka 5y agoPretty well I must say, modern C++ is very portable across different compilers. I wrote a quite complex piece of code two months ago, I fully tested it under GCC and Clang, and it built under MSVC without having to change almost anything. It's quite worse under C though, given that the standard way less comprehensive. You really have to stay away from those pesky Glibc extensions, and lots of stuff in the Standard C library is pretty unsafe or straight out broken (like strcpy and friends).
- Subsentient 5y agoIndeed, C++ has benefited enormously from having multiple implementations. If one compiler produces results different from another, generally speaking, you've just found an issue in that compiler. The multiple implementations serves as checks and balances in a way.
- yakubin 5y agoTo be fair, off the top of my head, Clang and GCC: - lex differently; - have different baselines for what code even compiles: e.g. in GCC an out-of-range hex escape sequence in an integer character constant generates a warning; in Clang it generates an error. Additionally, for a long time on Windows MinGW's std::random_device()() always returned 0, being a real-world depiction of <https://xkcd.com/221/ https://xkcd.com/221/>. So you compiled for Linux with GCC and everything was fine; then you compiled for Windows with MinGW and silently something broke, which resulted in a suspiciously big number of hash collisions. Then again, those are illustrations of a poorly written standard, not of the idea of a standard, which has multiple implementations, being bad.
- flohofwoe 5y agoOverall it's going well. While Clang, GCC and MSVC sometimes have surprising behaviour differences, once you look this stuff up in the C or C++ spec, these are almost guraranteed to be marked as implementation-defined- or undefined-behaviour (and if not then it's a compiler bug). Even being able to pinpoint what is implementation-defined or what is undefined-behaviour is an advantage of having multiple independent compiler implementations.