Cross-platform primitive data types in C++

前端 未结 7 2458
鱼传尺愫
鱼传尺愫 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:34

    Create a header file called types.h, and define all the fixed-size primitive types you need (int32, uint32, uint8, etc.). To support multiple platforms, you can either use #ifdef's or have a separate include directory for each platform (include_x86, include_x86_64, include_sparc). In the latter case you would have separate build configurations for each platform, which would have the right include directory in their include path. The second method is preferable, according to the "The C++ Gotchas" by Stephen Dewhurst.

    Just an aside, if you are planning to pass binary data between different platforms, you also have to worry about byte order.

    0 讨论(0)
提交回复
热议问题