Search code examples
cubuntugcctypesfixed-width

How can I use fixed-sized integers in C?


I'm trying to compile some code which contains the following declaration, because I would like count to be a guaranteed 32-bit integer:

int32 count;

However, this results in an error at compile time:

test.c:21: error: ‘int32’ undeclared (first use in this function)

Is there a particular compile-time option that I need to set for GCC, or an #include directive that will solve this? How can declare an integer of a fixed bit width on Ubuntu with GCC?


Solution

  • The int32 type isn't standard C - the standard equivalent is to #include <stdint.h> and use int32_t.

    However, as a POSIX system, on Ubuntu plain int is (at least) 32 bit so you could just use that.