Implementation:Alibaba MNN RapidJSON Inttypes
| Knowledge Sources | |
|---|---|
| Domains | JSON_Parsing, Compatibility |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
3rd_party/rapidjson/msinttypes/inttypes.h (316 lines) provides an ISO C99-compliant <inttypes.h> implementation for older Microsoft Visual C++ compilers that lack native support. This vendored header enables RapidJSON (and by extension Alibaba MNN) to use standard integer formatting macros (PRId64, PRIu32, etc.) across all supported Windows compiler versions.
Usage note: Vendored dependency used internally by MNN for JSON configuration parsing (model configs, LLM configs). Not directly imported by end users.
Purpose
Prior to Visual Studio 2013 (MSVC 1800), the <inttypes.h> header was not provided by the compiler. This header fills that gap by defining:
- Format conversion macros for
printfandscanffamilies - The
imaxdiv_ttype for integer division results - The
imaxabs()andimaxdiv()functions
Conditional Compilation
The header is guarded to only activate on MSVC:
#ifndef _MSC_VER
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif
// For MSVC >= 2013, defer to the native <inttypes.h>
#if _MSC_VER >= 1800
#include <inttypes.h>
#else
// ... provide compatibility definitions ...
#endif
Defined Macros
The header defines format specifier macros for the following integer types in groups for printf and scanf:
| Category | Example Macros |
|---|---|
| Signed decimal | PRId8, PRId16, PRId32, PRId64
|
| Unsigned decimal | PRIu8, PRIu16, PRIu32, PRIu64
|
| Unsigned hex | PRIx8, PRIx16, PRIx32, PRIx64
|
| Unsigned octal | PRIo8, PRIo16, PRIo32, PRIo64
|
intmax_t types |
PRIdMAX, PRIuMAX, PRIxMAX
|
| Pointer types | PRIdPTR, PRIuPTR, PRIxPTR
|
| scanf variants | SCNd8, SCNd16, SCNd32, SCNd64, etc.
|
Key Types and Functions
typedef struct {
intmax_t quot;
intmax_t rem;
} imaxdiv_t;
intmax_t imaxabs(intmax_t value);
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
intmax_t strtoimax(const char* nptr, char** endptr, int base);
uintmax_t strtoumax(const char* nptr, char** endptr, int base);
Dependencies
Includes the companion header msinttypes/stdint.h for the base integer type definitions.
License
BSD 3-Clause License. Copyright (c) 2006-2013 Alexander Chemeris. Modified by THL A29 Limited (Tencent Modifications), Copyright (C) 2015.
See Also
- Alibaba_MNN_RapidJSON_Stdint -- Companion stdint.h compatibility header
- Alibaba_MNN_RapidJSON_Core -- Core configuration header that may include these