Skip to content

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

Closed
@jothan

Description

@jothan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions