为什么固定宽度类型委托回原语?

van*_*nch 0 c++ visual-c++ stdint

Visual Studio 14stdint.h头有固定宽度整数类型定义,但如果你真的看有定义,他们只是委托回原语。定义如下:

typedef signed char        int8_t;
typedef short              int16_t;
typedef int                int32_t;
typedef long long          int64_t;
typedef unsigned char      uint8_t;
typedef unsigned short     uint16_t;
typedef unsigned int       uint32_t;
typedef unsigned long long uint64_t;
Run Code Online (Sandbox Code Playgroud)

那么,stdint.h如果它所做的只是回退到原始类型,是否有任何理由使用?我也知道Visual Studio不仅会在编译时替换这些定义,因为如果您尝试打印int8_t到控制台,则会得到一个Unicode字符而不是一个数字,因为它实际上只是一个signed char

编辑

因为人们指出,他们没有逻辑上可以定义的其他内容,我认为我的问题需要重申。

为什么在C ++规范中标明它将具有8、16、32和64位固定长度的整数的标头将这些整数定义为类型,根据定义,该类型可以是编译器想要的任何大小(放入别人在另一个问题中说的方式The compiler can decide that an int will a 71 bit number stored in a 128 bit memory space where the additional 57 bits are used to store the programmers girlfriends birthday.)?

Emi*_*ily 5

不同的平台对基元的定义不同。在一个平台上int可能是16位,而在另一个平台上可能是32位。如果严格依赖具有一定宽度的变量,则应使用中的类型stdint.h,这些类型将始终typedef正确匹配当前平台上其各自的基元。