I am coupling to a C library and would like to pass null pointers to a function. However, I want to pass a null pointer of type Ptr{<mytype>}. When I do that I end up with a convert error, because C_NULL of Ptr{Void}. It would be most straightforward if I could just use C_NULL everywhere.
Is there a way to write a custom convert function? I tried convert(::Type{Ptr{<mytype>}}, C_NULL) = Ref{<mytype>}(0)
but that didn’t seem to do anything.
There is no need for reinterpret here. The standard way to do it is just to use the constructor, as already shown, (which just bitcasts C_NULL to Ptr{Foo} but there is a reason why there exists higher-level interfaces).
So an example would be for the function foobar: ccall((:foobar, lib_include), Cint, (Ptr{foo}), C_NULL)
which does not work because C_NULL is of type Ptr{Void}.
So is there a way to convert C_NULL automatically to a type of Ptr{foo}?