Type safety could prevent nuclear war
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 5 00:27:29 PST 2016
On Friday, 5 February 2016 at 01:10:53 UTC, tsbockman wrote:
> All along I have been saying this is something that *compilers*
> should warn about. As far as I can recall, I never suggested
> using linters, sanitizers, changing the C standard - or even
> compiler plugins.
Well, compilers "should" only implement the standard, then they
"may" add extra static analysis.
The direction C and C++ takes is that increasing compilation
times by doing extra static analysis on every build isn't
desirable. Therefore compilers should focus on what is necessary
for code gen and optimization and sanitizers should focus on
correctness.
This is different from Rust, who do sanitization as part of their
compilation, but that makes the compiler more complicated and/or
much _slower_.
> (I did suggest the linker as an alternative, but you all have
> already explained why that can't work for C.)
It can work if you compile all source files with the same
compiler, that has historically not been the case as commercial
libraries would be compiled with other compilers or be
handwritten assembly.
C compilers that do Whole Program Analysis have dedicated linkers
that should be able to do extended type checking if the IR used
in the object file provides typing info. I don't know if Clang or
GCC does emit typing info though, but they _could_. Yes.
More information about the Digitalmars-d
mailing list