9 ms·
compiler-defined is extremely different from undefined.
by alisonkisk 5y ago
compiler-defined is extremely different from undefined.
- 10000truths 5y agoThat's the thing, though. What is considered undefined by the standard is NOT necessarily undefined by the compiler or target architecture. Type punning via union is UB in the standard, but well defined in `gcc`. Signed overflow is UB in the standard, but well defined in `gcc` with `-fwrapv`. Casting a void pointer to a function pointer is UB in the standard, but well defined for pretty much every non-MCU target arch (dlsym relies on it, after all!). Dereferencing a runtime-known NULL pointer is UB in the standard, but is well defined to trigger a segfault in pretty much every arch with an MMU. Etcetera, etcetera, etcetera.
- atq2119 5y ago> Dereferencing a runtime-known NULL pointer is UB in the standard, but is well defined to trigger a segfault in pretty much every arch with an MMU. This is incorrect for C/C++ though. Modern compilers definitely treat null dereferences as UB, with real consequences (e.g. eliminating redundant null pointer checks). The compiler is part of the architecture.
- pjmlp 5y agoThe fun starts when there is a new compiler version in town and that changes. Even Linus got to enjoy that fun.