Last active
April 18, 2019 16:29
-
-
Save krzyzanowskim/19ff9e298fb19fc95fbff7d01e28d242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Optional value is not initialized with nil, instead is initialized with 0 value | |
*/ | |
let p = UnsafeMutablePointer<UInt8?>.allocate(capacity: 0) | |
// p.initialize(repeating: nil, count: 1) | |
print("Value Type: \(type(of:p.pointee))") | |
if let value = p.pointee { | |
print("Value: \(value)") | |
} | |
/* Output: | |
Value Type: Optional<UInt8> | |
Value: 0 // probably garbage anyway. more like side effect | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Optional value is not initialized with nil, instead is initialized with 0 value | |
*/ | |
let p = UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>.allocate(capacity: 0) | |
print("Value Type: \(type(of:p.pointee))") | |
if let internalPointer = p.pointee { | |
print("Value: \(internalPointer)") | |
let internalValue = internalPointer.pointee | |
print("Internal Pointer Value Type: \(type(of:internalValue))") | |
print("Internal Pointer Value: \(internalValue)") | |
} | |
/* Output: | |
Value Type: Optional<UnsafeMutablePointer<UInt8>> | |
Value: 0x00007ffba550b880 | |
Internal Pointer Value Type: UInt8 | |
Internal Pointer Value: 36 // garbage value | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment