> On May 20, 2016, at 12:54 PM, Joe Groff via swift-users
> wrote:
>
>
>> On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users
>> 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
> On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users
> 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 viola
On 2016-05-20 08:55, Jens Alfke wrote:
On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users
wrote:
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 attri
> On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users
> wrote:
>
> 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
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
An working example,
let fm = NSFileManager.defaultManager()
var mh = mach_header() // Defined as C struct,
var lc = load_command() // Defined as C struct
var location = 0
if let data = fm.contentsAtPath("home/user/projects/some.o") {
data.getBytes(&mh, length: sizeof(mach_hea
> On May 19, 2016, at 10:00 AM, Ken Burgett via swift-users
> 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 th