我和这个答案的印象相同,size_t标准总是保证足够大以容纳给定系统的最大可能类型.
但是,此代码无法在gcc/Mingw上编译:
#include <stdint.h>
#include <stddef.h>
typedef uint8_t array_t [SIZE_MAX];
Run Code Online (Sandbox Code Playgroud)
错误:数组'array_t'的大小太大
我在这里误解了标准中的某些内容吗?被size_t允许为给定的实现是否过大?或者这是Mingw的另一个错误?
编辑:进一步的研究表明
typedef uint8_t array_t [SIZE_MAX/2]; // does compile
typedef uint8_t array_t [SIZE_MAX/2+1]; // does not compile
Run Code Online (Sandbox Code Playgroud)
这恰好是相同的
#include <limits.h>
typedef uint8_t array_t [LLONG_MAX]; // does compile
typedef uint8_t array_t [LLONG_MAX+(size_t)1]; // does not compile
Run Code Online (Sandbox Code Playgroud)
所以我现在倾向于认为这是Mingw中的一个错误,因为根据有符号整数类型设置最大允许大小没有任何意义.