Cannot check function address

Steven Schveighoffer schveiguy at gmail.com
Wed May 25 05:56:28 UTC 2022


On 5/25/22 1:40 AM, frame wrote:

> This would have been more visible if the compiler just says: "function 
> cannot be compared against null, only function pointer". That function 
> vs function pointer is too subtle.
> 

It's a case where the compiler can't divine what you were thinking when 
you wrote that code ;)

remember that the expression `fun` where fun is a *function*, and not a 
*function pointer*, is the equivalent of `fun()`.

It can't figure out that you really thought `fun` was a function 
pointer, maybe it thinks that you are missing an overload? Maybe fun 
actually is a no-arg function, and the result isn't comparable against 
null (or maybe it is, and it compiles and does something completely 
different!).

But I'm glad you discovered the issue.

-Steve


More information about the Digitalmars-d-learn mailing list