> On Mar 17, 2016, at 20:21 , Félix Cloutier <[email protected]> wrote: > >> Fortunately, when a type has a single invalid value for which no operations >> are valid, Swift already has a solution: Optionals. > > To me, this makes it sound like dereferencing an unsafe pointer is unsafe > only if the pointer is nil. (Nil does have the merit that it's generally one > of the only addresses known to be invalid, though.)
Okay, you're right, it was a bad description of the problem. UnsafePointer remains "unsafe" for a lot of other reasons. :-) > > One thing that I would worry about, though, is the case where dereferencing > address 0 is legal. My understanding is that Swift is aimed to be a systems > language, and this case is relatively frequent on embedded devices. Good point. Technically in the C standard, there must be some pointer value that cannot be the address of anything valid, whether or not it has a bit pattern of 0; the intent was that Swift's 'nil' would follow whatever C did for that platform rather than being 0. But I imagine a lot of embedded C code doesn't actually follow this rule (i.e. "NULL" will still give you the 0 address). I'm not very familiar with this space at all, but I'll look into it some more. If you know what existing compilers do here that'd be great to read. Jordan
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
