cpp-to-rust-book
cpp-to-rust-book copied to clipboard
Types table is incorrect
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++
A few more things to note:
- You can omit
int
aftershort
orlong
, 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
iscstdint
. - There is an equivalent to isize in Rust in C/C++ if you also assume POSIX compatibility. It's called
[std::]ssize_t
.