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

前端 未结 24 2954
无人及你
无人及你 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 05:10

    Nope, there is no standard for type sizes. Standard only requires that:

    sizeof(short int) <= sizeof(int) <= sizeof(long int)
    

    The best thing you can do if you want variables of a fixed sizes is to use macros like this:

    #ifdef SYSTEM_X
      #define WORD int
    #else
      #define WORD long int
    #endif
    

    Then you can use WORD to define your variables. It's not that I like this but it's the most portable way.

提交回复
热议问题