cpp-to-rust-book icon indicating copy to clipboard operation
cpp-to-rust-book copied to clipboard

Types table is incorrect

Open jplatte opened this issue 7 years ago • 1 comments

Equating char to i8 is wrong in two ways: Its signedness as well as its size are unspecified in the C and C++ standards.

According to an answer on Stack Overflow there are even real platforms out there with 16 or 32 bit chars. But AFAIK, for all the platforms Rust supports, you can at assume chars to be 8 bits in size, and thus signed char == i8, unsigned char == u8.

cppreference.com documentation about the char type (and other primitive types): C, C++

jplatte avatar Mar 12 '17 12:03 jplatte

A few more things to note:

  • You can omit int after short or long, and I haven't seen it not omitted in forever.
  • In C++, the fixed width integer types as well as size_t are in the std namespace (gcc and clang define them outside as well though AFAIK).
  • C++ standard library headers have no file endings. The equivalent to stdint.h is cstdint.
  • There is an equivalent to isize in Rust in C/C++ if you also assume POSIX compatibility. It's called [std::]ssize_t.

jplatte avatar Mar 12 '17 12:03 jplatte