News for hackers. Stuff that matters.
Re:The x86 architecture is the weirdo (2004) by notriddle on Wednesday April 20, 2022 @09:35AM (#31096714)
Structs aren’t the problem here. It’s the primitives.

You can take a pointer to an i32 and pass that pointer to C code as int32_t. This means it has to have the same alignment in Rust that it has in C.

Re:The x86 architecture is the weirdo (2004) by ncmncm on Wednesday April 20, 2022 @12:27PM (#31099370)
The topic at hand is, specifically, that nobody makes cores that enforce alignment restrictions anymore. So, it doesn't matter where the pointer goes. All that matters is if your compiler lays out its structs the same way as whoever compiled the code a pointer to one ends up in.

There are embedded targets that still enforce alignment restrictions, but you are even less likely to pass pointers between code compiled with different compilers, there.

Re:The x86 architecture is the weirdo (2004) by notriddle on Wednesday April 20, 2022 @02:42PM (#31101176)
> The topic at hand is, specifically, that nobody makes cores that enforce alignment restrictions anymore. So, it doesn't matter where the pointer goes.

Compilers can rely on alignment even if the CPU doesn't. LLVM does, which is why older versions of rustc had segfaults when repr(packed) used to allow taking references. While it would be pretty easy to get rustc to stop emitting aligned loads, getting Clang and GCC to stop emitting aligned loads might be trickier. https://github.com/rust-lang/rust/issues/27060