INT_FAST16_MAX does not reflect type size in MSVC 2010?

2

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

c
visual-studio-2010
c99
stdint
asked on Stack Overflow Jul 19, 2011 by Steve-o • edited Jan 7, 2020 by phuclv

1 Answer

1

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

answered on Stack Overflow Jan 7, 2020 by phuclv • edited Jan 7, 2020 by phuclv

User contributions licensed under CC BY-SA 3.0