我有一个结构,在定位
wasm
时必须是 16 字节对齐。
我该怎么做?
例如,我想在
wasm
上使用这个结构:
#[cfg(target_arch = "wasm32")] <- not sure about this
#[repr(c, align(16))]
struct Foo {...}
在所有其他架构上也是如此:
#[cfg(target_arch = "wasm32")] <- not sure about this
#[repr(c)]
struct Foo {...}
用cfg可以实现吗?如果是的话怎么办?
cfg_attr
:
#[cfg_attr(not(target_arch = "wasm32"), repr(C))]
#[cfg_attr(target_arch = "wasm32", repr(C, align(16)))]
struct Foo { ... }