Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signedness mismatch between core::ffi::c_char and libc::c_char #249

Open
jothan opened this issue Dec 21, 2024 · 0 comments
Open

Signedness mismatch between core::ffi::c_char and libc::c_char #249

jothan opened this issue Dec 21, 2024 · 0 comments

Comments

@jothan
Copy link

jothan commented Dec 21, 2024

I tried this code:

unsafe { libc::printf(c"%s".as_ptr(), line.as_ptr()) };

I expected to be able to compile the above code, but the compiler had a different opinion:

error[E0308]: mismatched types
  --> src/logging.rs:90:27
   |
90 |     unsafe { libc::printf(c"%s".as_ptr(), line.as_ptr()) };
   |              ------------ ^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
   |              |
   |              arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> index.crates.io-6f17d22bba15001f/libc-0.2.169/src/unix/mod.rs:694:12

It would seem that the latest libc 0.2.169 flipped its signedness of c_char from signed to unsigned for ESP-IDF:
rust-lang/libc@c66faeb

rustc should probably match this signedness change on ESP-IDF and update the definition somewhere around here: https://doc.rust-lang.org/beta/src/core/ffi/mod.rs.html#52

Doing a bit of searching around, I am about 80% sure that char is unsigned on the C side on ESP-IDF.

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (103cde010 2024-11-26) (1.83.0.0)
binary: rustc
commit-hash: 103cde01096863220765fd2e54519d011a5740ac
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 18.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant