Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make String type compatible with ARM?

Tags:

rust

arm

I need to compile a program for an ARM device. It seems to be failing here, perhaps because of the type difference on ARM?

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

The error is:

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 type difference and how do I fix it?

like image 639
Philip Kirkbride Avatar asked Dec 06 '17 21:12

Philip Kirkbride


1 Answers

You probably want to use std::os::raw::c_char instead of i8. (Though that may not be the right place to get the type from. libc::c_char seems to exist as well.)

The basic issue is that the char type in C can be signed or unsigned depending on the platform and that is reflected in the foreign function interface. Ideally you'd like to find a way to do the conversion without having to explicitly mention the type.

like image 88
Zalman Stern Avatar answered Nov 15 '22 09:11

Zalman Stern