Cannot check function address
Steven Schveighoffer
schveiguy at gmail.com
Wed May 25 02:42:26 UTC 2022
On 5/24/22 10:06 PM, frame wrote:
>
> Sorry, this was not affront, it was meant as my POV that you may have
> problems to get my problem because I have (as usually) forgot to make
> this more visible that some code was truncated.
OK, sorry to read into that ;)
> I tried your suggestion, as replied to Adam - the symbol is unique and
> it shows that correct location. It's not different from the error message.
Just to be pedantic, you tried that call in the *exact place* the assert
is failing to compile? D can be weird/surprising about name lookups.
>
> However, this error has nothing to do with `assert()`. In fact the
> compiler allows nothing than invocation or this error will be triggered.
> Even that fails:
The compiler is treating `fun` not as a function pointer, but as a
function. However, the type looks correct to me. I tried a simple
example on run.dlang.io, even with multiple modules, and seems to work
as expected.
>
> ```d
> // same error:
> auto test = cast(void*)fun;
> ```
>
try:
pragma(msg, typeof(fun));
If I do:
```d
extern(C) void foo(string) {}
pragma(msg, typeof(foo));
pragma(msg, typeof(&foo));
```
I get:
extern (C) void(string param)
extern (C) void function(string param)
The first is a function (yes, they have a type), and the latter is a
function pointer.
So that might give a clue whether the compiler thinks `fun` is a
function or a function pointer. D should *never* call a function pointer
without parentheses.
If you get the latter, yet your assert fails, then that is most
certainly a compiler bug. Again, important that you do this in the exact
place the assert fails to ensure the same name lookup situation.
-Steve
More information about the Digitalmars-d-learn
mailing list