Skip to content

u64 has an alignment of 8 bytes on i686-pc-windows-msvc instead of 4 as implied in the reference #1235

Open
@oberien

Description

@oberien

The rust reference states:

Most primitives are generally aligned to their size, although this is platform-specific behavior. In particular, on x86 u64 and f64 are only aligned to 32 bits.

-- https://doc.rust-lang.org/reference/type-layout.html

This is true for i686-unknown-linux-gnu:

> cat foo.rs
fn main() {
    println!("{}", std::mem::align_of::<u64>());
}
> rustc --target i686-unknown-linux-gnu foo.rs && ./foo
4

However, currently on i686-pc-windows-msvc the alignment of u64 is 8 bytes:

> rustc --target i686-pc-windows-msvc foo.rs
> foo.exe
8

The C++ compiler on that platform (at least the one UE uses) aligns u64 inside classes and structs to 4 bytes. I had expected repr(C) in rust do to the same (especially having read the part above from the reference) and was surprised it didn't. As I assume that some code somewhere relies on u64 being aligned to 8 bytes on that target, should the documentation in the reference be changed to reflect this difference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions