digitalmars.D - Re: C undefined behaviour
- bearophile <bearophileHUGS lycos.com> May 21 2011
- bearophile <bearophileHUGS lycos.com> May 21 2011
This follows: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=136205 Third part and last one: http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html http://www.reddit.com/r/programming/comments/hgk12/what_every_c_programmer_should_know_about/ This third article gives possible ideas for future safety improvements of D design :-) Every time you fix/avoid some of those problems, you erode away some costly and sometimes painful debugging time. So this work is ethically sound too. Bye, bearophile
May 21 2011
Regarding what I have said here: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=136205 A person has said me that Clang had the -ftrapu compiler switch to trap unsigned overflow too, but Chris removed it, because unsigned overflow is defined in the C standard. The discussion: http://comments.gmane.org/gmane.comp.compilers.clang.devel/4469 The comment by Chris Lattner:I'm sorry I was too terse. I don't want clang IR generation supporting language features that are not useful for C/C++ etc. Previously we had run-ins where you were trying to adapt the objc runtime generation code to work with your objective-smalltalk compiler, and this was causing the code to get contorted and be slow. I don't think it is ever a good idea to turn random unsigned multiplies into overflow checked ones, so I don't think that -ftrapu is useful for C programmers, so I think it should be removed. I *would* be supportive of an attribute on integer types that let programmers "opt in" to overflow checking on particular values. This would be incredibly cool and generally useful because it doesn't break the semantics of C. I just am opposed to a global option that changes how C works.
D doesn't need to follow such C design decisions. And even for C, Chris has broken and improved over some sclerotic design decisions of C compiler designers (even on little things, like Clang doesn't need a switch to compile C99 code!). So probably the generation of compiler writers successive to Chris will improve further. Compiler technology seems to move forward about ten times slower than other computer technology :-) Bye, bearophile
May 21 2011