[swift-users] Mapping C semantics to Swift

Joe Groff jgroff at apple.com
Thu May 19 12:22:28 CDT 2016


> On May 19, 2016, at 10:00 AM, Ken Burgett via swift-users <swift-users at swift.org> wrote:
> 
> I would like to know if a struct in Swift has any guarantee of contiguity, like a struct in C.  I am attempting to port a C program that makes many assumptions about the underlying semantics of C structs, and does things like overlaying an array over the struct using a cast, and then performs and cryptographic hashing of the entire struct by treating it as an array.
> 
> 1.  I a Swift struct contiguous?
> 
> 2.  If 1 above is true, can I somehow cast an array over the struct?

Swift structs have unspecified layout. If you depend on a specific layout, you should define the struct in C and import it into Swift for now.

-Joe


More information about the swift-users mailing list