INT_FAST16_MAX 不反映 MSVC 2010 中的类型大小?

发布于 2024-11-24 22:24:00 字数 1370 浏览 4 评论 0原文

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

http://fxr.watson.org/fxr/source/arm/include/_stdint.h?im=3

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

http://fxr.watson.org/fxr/source/arm/include/_stdint.h?im=3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2024-12-01 22:24:00

这是一个错误。 MSVC 是一个 C++ 编译器,Microsoft 从未专注于支持较新的 C 标准。 VS 2010 是第一个具有 的 MSVC 版本,因此毫不奇怪'会有很多问题。

Microsoft 软件架构师兼 ISO C++ 标准委员会主席 Herb Sutter 写道:

1。我们的主要目标是支持“作为 ISO C++98/C++11 子集的大部分 C99/C11。”

VC++ 2010 已经完全支持 C++98 的 C 子集,包括 和块中间的声明之类的内容。[*] C 的 C 子集++98 大约是 C95(与 C95 几乎没有不兼容;即,合法的 C95 代码在 C++98 中具有不同含义或无效的情况很少)加上一些 C99 功能,例如在块中间声明变量)。

读者问答:什么关于VC++和C99?

但是第一个真正支持某些 C99 功能的版本是VS 2013,更多功能在 VS2015 中引入

C99 一致性 Visual Studio 2015 完全实现了 C99 标准库,但依赖于 Visual C++ 编译器尚不支持的编译器功能(例如,未实现)的任何库功能除外。

Visual Studio 中 Visual C++ 的新增功能2015

但即使现在 VS 2017VS 2019 仍然不支持 C99/C11 的所有功能

Visual Studio 2017 中编译器对 C99 预处理器规则的支持不完整。我们正在彻底修改预处理器,并开始使用 /experimental:preprocessor 编译器开关在 Visual Studio 2017 版本 15.8 中发布这些更改。

Microsoft C++ 语言一致性表


我无法安装 VS2010,但我检查了 VS 2012,发现 stdint.h 中的定义已修复。这是 C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint.h 中的相关部分

...
typedef signed char        int_fast8_t;
typedef int                int_fast16_t;
typedef int                int_fast32_t;
typedef long long          int_fast64_t;
typedef unsigned char      uint_fast8_t;
typedef unsigned int       uint_fast16_t;
typedef unsigned int       uint_fast32_t;
typedef unsigned long long uint_fast64_t;
...
#define INT_FAST8_MIN    INT8_MIN
#define INT_FAST16_MIN   INT32_MIN
#define INT_FAST32_MIN   INT32_MIN
#define INT_FAST64_MIN   INT64_MIN
#define INT_FAST8_MAX    INT8_MAX
#define INT_FAST16_MAX   INT32_MAX
#define INT_FAST32_MAX   INT32_MAX
#define INT_FAST64_MAX   INT64_MAX
#define UINT_FAST8_MAX   UINT8_MAX
#define UINT_FAST16_MAX  UINT32_MAX
#define UINT_FAST32_MAX  UINT32_MAX
#define UINT_FAST64_MAX  UINT64_MAX
...
/*
 * Copyright (c) 1992-2012 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V6.00:0009 */

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

1. Our primary goal is to support "most of C99/C11 that is a subset of ISO C++98/C++11."

VC++ 2010 already fully supports the C subset of C++98, including things like <stdint.h> and declarations in the middle of a block.[*] The C subset of C++98 is approximately C95 (with very few incompatibilities with C95; i.e., there are very few cases where legal C95 code has a different meaning or is invalid in C++98) plus a few C99 features like declaring variables in the middle of blocks).

Reader Q&A: What about VC++ and C99?

But the first version that actually supports some C99 features is VS 2013 with more features introduced in VS2015

C99 Conformance Visual Studio 2015 fully implements the C99 Standard Library, with the exception of any library features that depend on compiler features not yet supported by the Visual C++ compiler (for example, is not implemented).

What's New for Visual C++ in Visual Studio 2015

But even nowadays VS 2017 and VS 2019 still don't support all features of C99/C11

The compiler’s support for C99 Preprocessor rules is incomplete in Visual Studio 2017. We're overhauling the preprocessor, and began shipping those changes in Visual Studio 2017 version 15.8 with the /experimental:preprocessor compiler switch.

Microsoft C++ language conformance table


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

...
typedef signed char        int_fast8_t;
typedef int                int_fast16_t;
typedef int                int_fast32_t;
typedef long long          int_fast64_t;
typedef unsigned char      uint_fast8_t;
typedef unsigned int       uint_fast16_t;
typedef unsigned int       uint_fast32_t;
typedef unsigned long long uint_fast64_t;
...
#define INT_FAST8_MIN    INT8_MIN
#define INT_FAST16_MIN   INT32_MIN
#define INT_FAST32_MIN   INT32_MIN
#define INT_FAST64_MIN   INT64_MIN
#define INT_FAST8_MAX    INT8_MAX
#define INT_FAST16_MAX   INT32_MAX
#define INT_FAST32_MAX   INT32_MAX
#define INT_FAST64_MAX   INT64_MAX
#define UINT_FAST8_MAX   UINT8_MAX
#define UINT_FAST16_MAX  UINT32_MAX
#define UINT_FAST32_MAX  UINT32_MAX
#define UINT_FAST64_MAX  UINT64_MAX
...
/*
 * Copyright (c) 1992-2012 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V6.00:0009 */

The header in VS 2013 is the same

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文