INT_FAST16_MAX 不反映 MSVC 2010 中的类型大小?
C99 将 int_fast16_t
定义为“通常最快且至少具有指定宽度的整数类型”,而 Microsoft 在 MSVC 2010 中将其定义为 32 位整数:
typedef char int_fast8_t;
typedef int int_fast16_t;
typedef int int_fast32_t;
typedef unsigned char uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
然而,Microsoft已设置限制以不反映实际的基础数据类型:
#define INT_FAST8_MIN (-0x7f - _C2)
#define INT_FAST16_MIN (-0x7fff - _C2)
#define INT_FAST32_MIN (-0x7fffffff - _C2)
#define INT_FAST8_MAX 0x7f
#define INT_FAST16_MAX 0x7fff
#define INT_FAST32_MAX 0x7fffffff
#define UINT_FAST8_MAX 0xff
#define UINT_FAST16_MAX 0xffff
#define UINT_FAST32_MAX 0xffffffff
人们会假设该标准的意图如下所示:
#define INT_FAST16_MIN (-0x7fffffff - _C2)
#define INT_FAST16_MAX 0x7fffffff
#define UINT_FAST16_MAX 0xffffffff
否则这会使常量完全多余?
编辑: NetBSD 设置示例:
/* Maximum values of fastest minimum-width signed integer types. */
#define INT_FAST8_MAX INT32_MAX
#define INT_FAST16_MAX INT32_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
C99 defines int_fast16_t
as an "integer types being usually fastest having at least the specified width", and Microsoft define it as a 32-bit integer in MSVC 2010:
typedef char int_fast8_t;
typedef int int_fast16_t;
typedef int int_fast32_t;
typedef unsigned char uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
Yet, Microsoft have set the limits to not reflect the actual underlying data type:
#define INT_FAST8_MIN (-0x7f - _C2)
#define INT_FAST16_MIN (-0x7fff - _C2)
#define INT_FAST32_MIN (-0x7fffffff - _C2)
#define INT_FAST8_MAX 0x7f
#define INT_FAST16_MAX 0x7fff
#define INT_FAST32_MAX 0x7fffffff
#define UINT_FAST8_MAX 0xff
#define UINT_FAST16_MAX 0xffff
#define UINT_FAST32_MAX 0xffffffff
One would assume that the intent of the standard would be to look like this:
#define INT_FAST16_MIN (-0x7fffffff - _C2)
#define INT_FAST16_MAX 0x7fffffff
#define UINT_FAST16_MAX 0xffffffff
Otherwise this makes the constants completely redundant?
Edit: Example of NetBSD setting as expected:
/* Maximum values of fastest minimum-width signed integer types. */
#define INT_FAST8_MAX INT32_MAX
#define INT_FAST16_MAX INT32_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个错误。 MSVC 是一个 C++ 编译器,Microsoft 从未专注于支持较新的 C 标准。 VS 2010 是第一个具有
的 MSVC 版本,因此毫不奇怪'会有很多问题。Microsoft 软件架构师兼 ISO C++ 标准委员会主席 Herb Sutter 写道:
但是第一个真正支持某些 C99 功能的版本是VS 2013,更多功能在 VS2015 中引入
但即使现在 VS 2017 和VS 2019 仍然不支持 C99/C11 的所有功能
我无法安装 VS2010,但我检查了 VS 2012,发现 stdint.h 中的定义已修复。这是
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint.h
中的相关部分VS 2013 中的标头是相同的
It's a bug. MSVC is a C++ compiler and Microsoft has never focused on supporting newer C standards. VS 2010 is the first MSVC version that has
<stdint.h>
so unsurprisingly there'd be many issues.Herb Sutter, a software architect at Microsoft, and chair of the ISO C++ standards committee, has written that
But the first version that actually supports some C99 features is VS 2013 with more features introduced in VS2015
But even nowadays VS 2017 and VS 2019 still don't support all features of C99/C11
I couldn't install VS2010 but I checked with VS 2012 and see that the definitions in stdint.h was fixed. Here's the relevant part in
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint.h
The header in VS 2013 is the same