On Wednesday, 25 May 2022 at 02:42:26 UTC, Steven Schveighoffer wrote:

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.

Yes, of course ;-)


try:

pragma(msg, typeof(fun));

Outputs:
```
extern (C) void function(...)
```


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.

But the compiler would complain if I call it as a type? And how could it call it later without an address to it - this works.

D should never call a function pointer without parentheses.

I'm very good in finding weird bugs ;-) Unfortunately, I cannot make an example. I already tried some changes/simplifications but cannot reproduce it outside the project.

But how can I help the compiler to use it as correct type? On invocation with arguments all works fine, but checking if the pointer is not null fails. It not even works with an assignment. Could some `static if()` maybe help or some asm trick?

Reply via email to