How to a pass a nil pointer to a C API in Swift?
More specifically, I'm trying the following:
import Accelerate
let v = [1.0, 2.0]
var m = 0.0
var sd = 0.0
// 3rd arg is of type: UnsafeMutablePointer<Double>?
vDSP_normalizeD(v, 1, nil, 0, &m, &sd, vDSP_Length(v.count))
Documentation for vDSP_normalizeD
is found here.
This method of passing nil seems valid for earlier versions of Swift as in this answer. However using Xcode v10.1 / Swift v4.2.1 it gives the following error message:
Nil is not compatible with expected argument type 'UnsafeMutablePointer'
The following solution does not work either:
let p: UnsafeMutablePointer<Double>? = nil
vDSP_normalizeD(v, 1, p, 0, &m, &sd, vDSP_Length(v.count))
giving the following error message:
Value of optional type 'UnsafeMutablePointer?' must be unwrapped to a value of type 'UnsafeMutablePointer'
In earlier versions of Swift the following was possible:
let p = UnsafeMutablePointer<Double>(nil)
but it now generates the following error:
Ambiguous use of 'init'
So, my question is - how do I pass a nil pointer to a C API using a modern version of Swift?