Rust libc使用
那么,为什么 Rust libc 在将结构体传递给系统 libc 时使用
repr(packed)
,如此处所示,用于结构体,并将其传递给系统libc。例如,utsname使用repr(packed)
,然后在fn uname中使用。
根据此处提到的文档。repr(packed) forces Rust to strip any padding, and only align the type to a byte. This may improve the memory footprint, but will likely have other negative side-effects.
In particular, most architectures strongly prefer values to be aligned. This may mean the unaligned loads are penalized (x86),
那么,为什么 Rust libc 在将结构体传递给系统 libc 时使用
repr(packed)
而不是 repr(C)
?