Re:What Every C Programmer Should Know About Undefined Behav...
by lmm on Thursday January 05, 2017 @10:30AM
(#13327856)
The standard imposes no requirements on how an implementation behaves with a program that does that. While I would agree that that makes C a not-very-useful language for most modern applications programming, what requirements would you have the standard impose? On some architectures reading * P might trap/segfault, so you cannot require that this line be harmless. Other architectures might read a value into dead (e.g. embedded systems with no MMU/segmentation) and continue harmlessly, so you cannot require that the line have some effect. If you make a requirement that if the line segfaults that counts as an externally visible effect then you basically disallow the compiler from reordering memory accesses at all, which could cost a lot of performance. Java shows it's more-or-less possible to achieve close-to-C performance while imposing consistent requirements on null dereferences, but only with the help of a highly-tuned JIT that consumes quite a bit of memory and startup time, which could be prohibitive for many environments.
[ Parent
| on HN ]
There are no comments on this comment yet.