3 ms·
I've long believed that all compliant compilers should implement all undefined behaviour as an attempt to format the hard drive. It makes bugs much easier to de
by ajarmst 12y ago
I've long believed that all compliant compilers should implement all undefined behaviour as an attempt to format the hard drive. It makes bugs much easier to detect in testing. Bugs that ship will mask themselves from customers, and many critical security bugs will be self-limiting and reduce the amount of data exposed.
- DSMan195276 12y agoThat's not really how undefined behavior works though. In general, undefined behavior is used to optimize code by assuming it never happens and thus ignore that case. "implementing" undefined behavior to format the hard drive would mean that compilers would have to implement checks for every possible type of undefined behavior whenever you do something that has a undefined case (Ex. Every time you dereference a pointer). The slow-down would be fairly noticeable.
- Dewie 12y agoI think it was a joke, so not something that should be taken literally.
- deleted 12y ago[deleted]
- lomnakkus 12y agoThat's not really viable. Otherwise all compiler vendors would have already implemented a "error-on-all-undefined-behavior" switch. (See other poster.) Compiler vendors are trying to implement sanity checks and such, but there's only so much they can do given that whether something is "undefined behavior" may depend on run-time values. EDIT: Btw, this is what happens if you ever have a language with "undefined behavior". On the upside it can probably perform (given a correct program) like nobody's business on any given architecture (from x86 to DSPs with 10-bit chars).
- nostrademons 12y agoIf all compliant compilers implement undefined behavior as an attempt to format the hard drive, it's not exactly undefined behavior any more, right? The behavior has been defined as "format the hard drive". The HTML5 spec is a good example of the pros and cons of defining everything. On one hand, you can be sure that every compliant parser will parse the document the same way, including incredibly malformed documents. On the other, it significantly increases the complexity of the implementation, and it eliminates certain optimization opportunities. On the third hand - it doesn't seem to have discouraged page authors from writing incredibly malformed HTML. If it had discouraged page authors from writing incredibly malformed HTML, then a significant portion of the web would break.
- kazinator 12y agoThe behavior is still formally undefined; it has been locally defined by the implementor as a documented extension. So to speak, it is "evil-implementor-defined", but not "standard-defined". :)
- dllthomas 12y agoThere was a version of GHC (dev, never released) that would delete your source when there was a type error. Haskell on hardcore mode...