Type safety could prevent nuclear war
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 4 20:25:09 PST 2016
On Friday, 5 February 2016 at 01:33:14 UTC, tsbockman wrote:
> As to the ".di" stuff - I've not used them. Care to educate me?
> How can they cause similar problems?
Well, technically, a .di file is just a .d file renamed, but it
tends to have the bodies stripped out. Separate compliation is a
supported feature of D.
The way you'd do it is something like this:
struct Foo {
float a;
float b;
}
void bar(Foo* f) {
f.b = whatever;
}
Then compile it with -lib and make a "header" file manually:
struct Foo {
double a;
double b;
}
void bar(Foo*);
You can now create D modules that import this and link against
the compiled library. Very similar to C's model...
But I redefined Foo! The name mangling won't catch this. bar will
be mangled to take `Foo` as an argument and the linker will catch
if we change that, but it doesn't know what Foo actually is.
By changing that, we introduce the problem.
> 314 definitely has potential. Should we start an "Underhanded
> D" contest? Sounds like bad marketing, but a lot of fun :-P
it might be :)
More information about the Digitalmars-d
mailing list