Make String type compatible with ARM?

I need to compile a program for an ARM device. It seems like it is failing here, perhaps due to the type difference on ARM?

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

Error:

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`

What is the difference in type and how to fix it?

+4
source share
1 answer

You might want to use std::os::raw::c_charinstead i8. (Although this may not be a suitable place to get type. libc::c_charAlso exists.)

The main problem is that the type charin C can be signed or unsigned depending on the platform and reflected in the interface of the external function. Ideally, you would like to find a way to do the conversion without explicitly specifying a type.

+5
source

Source: https://habr.com/ru/post/1690352/


All Articles