On 04.02.2016 23:57, tsbockman wrote:
http://www.underhanded-c.org/#winner

Actually, I'm surprised that this works even in C - I would have
expected at least a compiler (or linker?) warning; this seems like it
should be easy to detect automatically.

You can do the same thing in D, using extern(C) to get no mangling:

main.d:
----
alias float_t = double;
extern(C) float_t deref(float_t* a);
void main()
{
    import std.stdio: writeln;
    float_t d = 1.23;
    writeln(deref(&d)); /* prints "1.01856e-314" */
}
----

deref.d:
----
alias float_t = float;
extern(C) float_t deref(float_t* a) {return *a;}
----

Command to build and run:
----
dmd main.d deref.d && ./main
----

Reply via email to