Type safety could prevent nuclear war

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 4 22:38:19 PST 2016


On Fri, Feb 05, 2016 at 12:14:11AM +0000, tsbockman via Digitalmars-d wrote:
[...]
> This isn't even a particularly expensive (in compile-time costs) check
> to perform anyway; all that is necessary is to store a temporary table
> of symbol signatures somewhere (it doesn't need to be in RAM), and
> check that any duplicate entries are consistent with each other before
> linking.

That's a lot more expensive than you think. There's a reason most modern
linkers do not do full cross-referencing of symbols -- because doing so
would be excruciatingly slow and consume gobs of memory. Even a 32GB
machine would not be able to hold *all* the symbols in some very large
software projects, and looking things up on disk is unacceptably slow
for software of those sizes. Most modern linkers instead use faster
algorithms that rely on clever scheduling of the order of symbol
resolution, just so they *don't* have to cross-reference all symbols at
once.

Besides, all this is unnecessary work. All you need to do is to have C
compilers mangle function names.  Mission accomplished.

(However, this *will* break a lot of existing inter-language code that
rely on being able to spell out symbols explicitly. So it probably will
not fly.  But, in theory, it *is* possible...)

And to paraphrase one of my favorite Walter quotes: fixing inconsistent
function signatures is only plugging one hole in a cheese grater. C has
far more dangerous gotchas than just function signature mismatches.


T

-- 
They say that "guns don't kill people, people kill people." Well I think
the gun helps. If you just stood there and yelled BANG, I don't think
you'd kill too many people. -- Eddie Izzard, Dressed to Kill


More information about the Digitalmars-d mailing list