Skip to content

Instantly share code, notes, and snippets.

@telliott99
Created December 17, 2015 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telliott99/f87517149f899c80a7fc to your computer and use it in GitHub Desktop.
Save telliott99/f87517149f899c80a7fc to your computer and use it in GitHub Desktop.
pointer demo
import Foundation
func t() {
let a: [Int32] = [1,2,3,4,5]
let n = Int32(a.count)
Swift.print("Swift: a = \(a)")
let ptr = UnsafeMutablePointer<Int32>(a)
f1(ptr, n)
f2(ptr, n)
f1(ptr, n)
Swift.print("Swift: a = \(a)")
let b: [Double] = [0, 0, 0, 0, 0]
let ptr2 = UnsafeMutablePointer<Double>(b)
f3(ptr,ptr2,n)
Swift.print("Swift b: ", terminator: "")
for v in b {
print(String(format: "%.3f", v), terminator: " ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment