What does the C++ standard state the size of int, long type to be?

前端 未结 24 2256
无人及你
无人及你 2020-11-21 04:42

I\'m looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler.

24条回答
  •  庸人自扰
    2020-11-21 04:53

    We are allowed to define a synonym for the type so we can create our own "standard".

    On a machine in which sizeof(int) == 4, we can define:

    typedef int int32;
    
    int32 i;
    int32 j;
    ...
    

    So when we transfer the code to a different machine where actually the size of long int is 4, we can just redefine the single occurrence of int.

    typedef long int int32;
    
    int32 i;
    int32 j;
    ...
    

提交回复
热议问题