Cross-platform primitive data types in C++

前端 未结 7 2438
鱼传尺愫
鱼传尺愫 2021-02-14 07:04

Unlike Java or C#, primitive data types in C++ can vary in size depending on the platform. For example, int is not guaranteed to be a 32-bit integer. Various compi

7条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 07:15

    Part of the C99 standard was a stdint.h header file to provide this kind of information. For instance, it defines a type called uint32_t. Unfortunately, a lot of compilers don't support stdint.h. The best cross-platform implementation I've seen of stdint.h is here: http://www.azillionmonkeys.com/qed/pstdint.h. You can just include that in your project.

    If you're using boost, I believe it also provides something equivalent to the stdint header.

提交回复
热议问题