How to use a function without their sources

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Jan 18 10:17:56 PST 2013


On 1/18/13, nazriel <spam at dzfl.pl> wrote:
> extern(C) void _D3lib3fooFZv();
>
> void main() {
> 	_D3lib3fooFZv();
> }

That's a *terrible* idea, you are calling a D function using the C
convention, you're going to have all sorts of problems. extern(D) is
not just used for mangling, it's also used for designating how
parameters are passed to and results are returned from a function (via
stack/registers). E.g.:

import std.stdio;

int foo(int x, int y)
{
    return x + y;
}

alias extern(C) int function(int, int) Func;

void main()
{
    Func func = cast(Func)&foo;
    writeln(func(1, 2));
}

$ rdmd test.d
> object.Error: Access Violation


More information about the Digitalmars-d-learn mailing list