什么数据类型是32位操作系统中的16位和64位操作系统中的32位?

Cod*_*777 -1 c++ 32bit-64bit visual-c++

我正在寻找一种数据类型(将用作索引),它应该是32位操作系统中的16位和64位操作系统中的32位.我使用VS2010,我知道可以使用HALF_PTR,但是当用于索引时听起来不太好我仍然可以将它定义为更有意义的名称,但在此之前我可以使用任何已定义的数据类型这个目的?

Ker*_* SB 5

您可以使用traits创建适合您系统的类型别名:

#include <cstdint>

template <unsigned int> struct HalfPtrImpl;
template <> struct HalfPtrImpl<4> { typedef uint16_t type; };
template <> struct HalfPtrImpl<8> { typedef uint32_t type; };

typedef HalfPtrImpl<sizeof(uintptr_t)>::type HalfPtr;
Run Code Online (Sandbox Code Playgroud)

现在HalfPtr用作你的类型.

(您可以通过使用std::conditional几次来快速完成上述操作.许多方法可以为这只猫提供皮肤.)