Type safety could prevent nuclear war

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 4 15:59:06 PST 2016


On Thu, Feb 04, 2016 at 11:47:53PM +0000, tsbockman via Digitalmars-d wrote:
[...]
> You can do the same thing in D if you try, but it's not natural at all
> to use `extern(C)` for *internal* linkage of an all-D program like
> that.
> 
> Any competent reviewer would certainly question why you were using
> `extern(C)`; this scores much lower in "underhanded-ness" than the
> original C program.
> 
> Even so, I think that qualifies as a compiler bug or a hole in the D
> spec.

Nah... while D, by default, tries to be type-safe and prevent guffaws
like the above, it *is* also a systems programming language (or at
least, that's one of the stated goals), so it does allow you to go under
the hood to do things that you normally aren't allowed to do.

Linking to foreign languages is a use case for allowing extern(C)
function names: if you know the mangling scheme of the target language,
you can declare the mangled name under extern(C) and that will allow D
code to call functions written in the target language directly.
Otherwise you'd have to change the compiler (and wait for the next
release, etc.) before you could do that.


T

-- 
Do not reason with the unreasonable; you lose by definition.


More information about the Digitalmars-d mailing list