Avatar
@t.ae UnsafeMutablePointer のコンストラクタで & 暗黙変換で得たポインタによるアクセスは未定義動作ですよ。引数の & による暗黙のポインタ変換はその関数スコープでしか利用できないです。(なので関数引数でしか & が使えないようにしていると思われる) (edited)
5:20 AM
Important The pointer created through implicit bridging of an instance or of an array’s elements is only valid during the execution of the called function. Escaping the pointer to use after the execution of the function is undefined behavior. In particular, do not use implicit bridging when calling an UnsafeMutablePointer initializer.
var number = 5 let numberPointer = UnsafeMutablePointer<Int>(&number) // Accessing 'numberPointer' is undefined behavior.