Integer type that is always the same as C's "int"

Hi,

so i'm interfacing with a glib based library using the cpp crate. At one point, this library returns a "gint", which is basically glib's renamed version of C's int. Unfortunately, int's size depends on the platform and the compiler, and it's either 16, 32, or 64 bits long. Now if i want to use that value in rust, what type should it be? is there some type that's platform dependant and will always be the same size as whatever the c++ compiler used by the cpp crate uses as its int type?

kind regards :slight_smile:

1 Like

thanks, so gcc/clang guarantee that it's always 32bit?

The libc crate specializes its type definitions for each target platform. It happens that all supported platforms currently use type c_int = i32, but this is not guaranteed for all platforms everywhere.

4 Likes

For a concrete example where there is a difference, see c_long:

4 Likes

BTW, you don't need the libc crate. std::os::raw::* has these type definitions.

3 Likes