Does "Int" in C always have the same number of bits as OS bits?

On a system, does the "int" data type in C always have the same number of bits as the OS bits?

Thanks!

+4
source share
4 answers

No, not necessarily. For an obvious example, if you use a 32-bit compiler on a 64-bit OS, you will usually have 32-bit ints.

The requirements in the C standard are pretty minimal. In addition to the minimum size requirements, there (ยง6.2.5 / 5):

An object

A '' plain intis the natural size suggested by the runtime architecture (large enough to contain any value in the range from INT_MINto INT_MAX, as defined in the header <limits.h>).

, 64 , long long.

, int32_t, . , , 32 , , .

, . , 64- , long long int_fast64_t ( , 32- ). , 64- , 64- .

32- () , . int32_t 32 , 64- 64- , 64- , , 64- , 32-. ( ) , int32_t, . ( 32- ) , 64- , , , int_fast32_t - , 32 .

, , - "", 64 . , , , 64- , 32- : , int64_t, , , int_fast64_t, , , (, 128- ) () 64 , .

+7

. ( : ). int, unsigned .. , int 16, 32 .

, . , <stdint.h> , , int32_t, uint8_t ..


  • , 2014-02-14, <http://www.cplusplus.com/reference/cstdint/>
+3

. , , .

+2

64- Debian

#include <stdio.h>

int main() {
    #define printSize(aType) printf("sizeof " #aType " = %ld\n", sizeof(aType))
    printSize(void*);
    printSize(char);
    printSize(short);
    printSize(int);
    printSize(long);
    printSize(long long);
}

:

sizeof void* = 8
sizeof char = 1
sizeof short = 2
sizeof int = 4
sizeof long = 8
sizeof long long = 8

, int 64 64- , , int . , .


, . C. :

  • char 8 ( , ).

  • long long 64 .

, , long int ..

0

Source: https://habr.com/ru/post/1526993/


All Articles