Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Declare a 32-bit Integer in C

Tags:

c

portability

What's the best way to declare an integer type which is always 4 byte on any platforms? I don't worry about certain device or old machines which has 16-bit int.

like image 339
ZZ Coder Avatar asked Aug 04 '09 18:08

ZZ Coder


People also ask

How do you represent a 32-bit integer?

A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295]. The signed integer is represented in twos complement notation.

How do I save a 32-bit integer?

32-bit signed integer type is used to store negativ or pozitiv whole number. 32-bit integer and his value range: from -2147483648 to 2147483647.

How do I create a 32-bit signed integer in C++?

Microsoft C/C++ features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intN type specifier, where N is 8, 16, 32, or 64.

Is C Language 32-bit?

Pointers. The ARMv7-M architecture used in mbed microcontrollers is a 32-bit architecture, so standard C pointers are 32-bits.

Is int a 32-bit data type?

int is 32 bits in size. long , ptr , and off_t are all 64 bits (8 bytes) in size.


2 Answers

#include <stdint.h>  int32_t my_32bit_int; 
like image 195
Corey D Avatar answered Sep 20 '22 11:09

Corey D


C doesn't concern itself very much with exact sizes of integer types, C99 introduces the header stdint.h , which is probably your best bet. Include that and you can use e.g. int32_t. Of course not all platforms might support that.

like image 37
nos Avatar answered Sep 22 '22 11:09

nos