On Thursday, 4 February 2016 at 23:59:06 UTC, H. S. Teoh wrote:
On Thu, Feb 04, 2016 at 11:47:53PM +0000, tsbockman via
Digitalmars-d wrote: [...]
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
I'm not saying that `extern(C)` is bad in general; I understand
why it's necessary.
I'm saying that anonymous' example
(http://forum.dlang.org/post/[email protected])
showcases a hole in the spec, because in it the D compiler has
access to the full source code of the function being linked to,
and doesn't bother to verify that its signature in main.d is
compatible with the definition in deref.d.
If the D compiler does *not* have access to the function's
definition, then obviously it cannot perform this verification.