How to check in Rust if architecture is 32 or 64 bit?

﹥>﹥吖頭↗ 提交于 2019-11-26 21:51:56

问题


If there a conditional check for whether processor is 32-bit or 64-bit? I'm looking for kind of configuration check like e.g. #cfg[x86] or cfg[x64].


回答1:


The #[cfg(target_pointer_width = "64")] from the cfg section in the Rust reference seems like a likely solution. It is based on the size of a pointer (as well as isize and usize), which should correspond to the architecture.




回答2:


You should check the Rust Reference chapter on conditional compilation:

target_arch = "..." - Target CPU architecture, such as "x86", "x86_64", "mips", "powerpc", "powerpc64", "arm", or "aarch64". This value is closely related to the first element of the platform target triple, though it is not identical.



来源:https://stackoverflow.com/questions/41896462/how-to-check-in-rust-if-architecture-is-32-or-64-bit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!