[swift-users] UnsafeMutablePointer<String> vs. UnsafeMutablePointer<Int>
Adrian Zubarev
adrian.zubarev at devandartist.com
Sat May 21 03:48:14 CDT 2016
I played around with UnsafeMutablePointer and realized one behavior:
let pString = UnsafeMutablePointer<String>.alloc(1)
pString.initialize("test")
pString.predecessor().memory // will crash ax expected
pString.predecessor() == pString.advancedBy(-1) // true
pString.destroy()
pString.dealloc(1)
where
let iInt = UnsafeMutablePointer<String>.alloc(1)
iInt.initialize("test")
iInt.predecessor().memory // will not crash
iInt.predecessor() == iInt.advancedBy(-1) // true
iInt.predecessor().memory = 42 // did I just modified some memory I don't own?
iInt.destroy()
iInt.dealloc(1)
Is this intended? This is really the case where its unsafe.
--
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160521/b82e14ce/attachment.html>
More information about the swift-users
mailing list