rust - 使 String 类型与 ARM 兼容?

标签 rust arm

我需要为 ARM 设备编译程序。它似乎在这里失败了,也许是因为 ARM 上的类型差异?

unsafe { Ok(String::from(try!(CStr::from_ptr(buf.as_ptr() as *const i8).to_str()))) }

错误是:

694 |         unsafe { Ok(String::from(try!(CStr::from_ptr(buf.as_ptr() as *const i8).to_str()))) }
    |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`

什么是类型差异,我该如何解决?

最佳答案

您可能想使用 std::os::raw::c_char而不是 i8。 (虽然这可能不是从中获取类型的正确位置。libc::c_char 似乎也存在。)

基本问题是 C 中的 char 类型可以有符号或无符号,具体取决于平台,这反射(reflect)在外部函数接口(interface)中。理想情况下,您希望找到一种无需明确提及类型即可进行转换的方法。

关于rust - 使 String 类型与 ARM 兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47684111/

相关文章:

asynchronous - 如何使用 futures.rs 和 Redis PubSub 为阻塞调用实现 future 流?

random - 特征 `rand_core::CryptoRng` 未针对 `OsRng` 实现

visual-studio-code - Rust-analyzer 错误 "could not resolve macro ` $crate::format_args`"是什么意思,我该如何解决?

rust - 在dylib中调用外部函数

c - 如何在 mbed-cli 上编译 hal mbed

rust - 我可以在不使用泛型类型的情况下获得多特征实例的特征对象吗?

embedded - uboot-uart.bin 和 uboot.bin 之间的区别?

c - ARM 程序集 - bl 分支到错误的地址

linux - Linux 内核上的 arm64 中的调试异常 (ptrace single_step) 如何工作?

assembly - 在汇编中除以 10 未给出正确结果