[swift-evolution] Proposal: Add Initializers For Converting UnsafePointers to Int and Unit

Dmitri Gribenko gribozavr at gmail.com
Wed Dec 9 15:55:46 CST 2015


On Wed, Dec 9, 2015 at 1:15 PM, Brent Royal-Gordon via swift-evolution
<swift-evolution at swift.org> wrote:
>> On the off chance you're trying to do loads from unaligned UnsafePointers, that's undefined in the current interface. You'll need to memcpy to well-aligned memory first.
>
> The buffer I’m accessing is UInt8, which I believe is always aligned, right?
>
> C:
>
>         typedef struct MIDIMetaEvent
>         {
>                 UInt8           metaEventType;
>                 UInt8           unused1;
>                 UInt8           unused2;
>                 UInt8           unused3;
>                 UInt32          dataLength;
>                 UInt8           data[1];
>         } MIDIMetaEvent;
>
> Swift:
>
>         public struct MIDIMetaEvent {
>
>             public var metaEventType: UInt8
>             public var unused1: UInt8
>             public var unused2: UInt8
>             public var unused3: UInt8
>             public var dataLength: UInt32
>             public var data: (UInt8)
>             public init()
>             public init(metaEventType: UInt8, unused1: UInt8, unused2: UInt8, unused3: UInt8, dataLength: UInt32, data: (UInt8))
>         }

FWIW, this problem looks very much like one for which we did the
CoreAudio overlay: stdlib/public/SDK/CoreAudio/CoreAudio.swift

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list