3 ms·
I changed it to: let foo = &mut array[0] as *mut u8 as *mut Foo; (*foo).a += 1; and the IR has the same undefined behavior: https://godbolt.or
by AndyKelley 9y ago
I changed it to:
let foo = &mut array[0] as *mut u8 as *mut Foo;
(*foo).a += 1;
and the IR has the same undefined behavior: https://godbolt.org/g/5Bv3FL https://godbolt.org/g/5Bv3FL
- steveklabnik 9y agoYeah I mean, to be clear, it's cool zig checks this stuff. Unsafe code is extremely dangerous, in a variety of ways. Luckily, outside of FFI, it's very rare to actually need to write it, though that does of course depend on what exactly you're doing. We hope, in the future, to basically have tooling here that can detect when you do something UB, and warn you. As we're still sorting out the memory model, etc, it's not here yet, but it's certainly on the agenda.