Cannot check function address
Steven Schveighoffer
schveiguy at gmail.com
Tue May 24 19:09:52 UTC 2022
On 5/24/22 2:54 PM, frame wrote:
> I have a function slot that may be loaded via a shared library.
> I want to check if that function has an address but compiler (DMD 2.100,
> Windows) instead tries to invocate the function?
>
> ```d
> // --- module a:
> alias F = extern (C) void function(string param);
> F fun = someLibLoad!F("name");
>
> assert(fun !is null); // compiles (also works in runtime)
This doesn't seem valid for module-level code, assert is an instruction,
not a declaration.
>
> // --- module b:
> import a;
>
> // same code:
> //
> // error: missing argument for parameter #1: ... with 2.098.1 or
> // error: too few arguments, expected `5`, got `0` ... with 2.100
> assert(fun !is null);
> ```
>
> Usually that works fine as shown in module A but for some reason not in
> module B.
> Workaround ideas? I tried casting to void* or ptrdiff_t but the compiler
> always tries to call the function -.-
`expected 5 got 0` suggests it is finding some other `fun`, as `a.fun`
only takes a single parameter.
Try `std.traits.fullyQualifiedName!fun` to see where it's coming from.
-Steve
More information about the Digitalmars-d-learn
mailing list