Closed
Description
Now that #8666 is in place, there is not a good way to make a NULL extern "C" fn
. You can do it, but you have to specify the whole type of the function pointer again with as
:
0 as extern "C" fn(args...) -> ReturnType
using std::ptr::null()
will not compile, and gives:
hello_nullfuncptrs.rs:4:8: 4:25 error: mismatched types: expected `extern "C" fn(int, int) -> int` but found `*<V0>` (expected extern fn but found *-ptr)
Some C APIs really do need to have NULL passed in for function pointers. Right now, using as
like the code above is the only way to create such a null pointer; For those cases where you need to pass a NULL into a C API, it would be nice if std::ptr::null()
would work for that, without having to repeat the whole type (including all arguments and return type) of the function pointer in order to do it.
UPDATE: Title amended by @nikomatsakis to reflect the real issue at hand.