> On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users 
> <swift-users@swift.org> wrote:
> 
> I have been told that the in-memory layout of a Swift struct is 'undefined', 
> so the C style of aliasing an array over a struct and iterating across the 
> struct is a definite no-no.  Not surprising, since aliasing violates all 
> type-safe rules.
> 
> So, if you have this situation, you must address it on a case-by-case basis.  
> In my case, converting a hash algorithm from C to Swift, the required C 
> struct morphs into a Swift class, with a member function 'as_C_byte_array' 
> which answers an array of the required form.  Internally, this function will 
> shift and mask class attributes in order to build the necessary result.

That's not necessary. You can leave the struct defined in C and import it into 
Swift. Swift will respect C's layout.

-Joe

> Ugly, but I must preserve the semantics exactly if I hope to generate the 
> exact same hash as the C version.
> 
> -- 
> Ken Burgett
> Principal Software Engineer
> Email: k...@iotone.io
> Office: 530.693.4449
> Mobile: 831.332.6846
> URL: www.iotone.co
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to