[swift-evolution] [late pitch] UnsafeBytes proposal
atrick at apple.com
Wed Aug 24 14:09:52 CDT 2016
> On Aug 23, 2016, at 9:56 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>> On Aug 23, 2016, at 5:28 PM, Trent Nadeau via swift-evolution <swift-evolution at swift.org> wrote:
>> For an architecture to be C-compatible, its byte size must be 8 bits. Given the need to run C everywhere and that almost all OSes are written in C, it's a very safe assumption that a byte equals 8 bits. At this point, I think the only thing where that's not true are certain micro-controllers for which there are specialized compilers.
> Right, Swift depends on Clang. Clang assumes that the target machine has 8-bit-byte-addressable memory. I don’t see any reason that Swift should pretend to work on the (only historically interesting) systems that had 9-bit (or any other weird number) addressable units.
To be fair to Jason, I think he just wants the language to be explicit about a byte being an 8-bit numeric value.
That’s not quite what I’m trying to convey though. I want bytes to refer only to the in-memory layout of values of any type in 8-bit chunks per the ABI. Typically, loading a byte without imposing any type on the in-memory value should produce a UInt8 value. Swift should not have a Byte type because it would contradict this meaning and serve no purpose.
I’ve been working with developers who need to parse or stream binary data. It’s a common use case. What I’m proposing perfectly matches the intuition of these developers who are already using the same concepts and terminology that I am.
More information about the swift-evolution