【发布时间】:2012-04-11 15:51:42
【问题描述】:
malloc 定义如下:
void *malloc(size_t size);
http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html
size_t 定义(stddef.h):
size_t: Unsigned integer type of the result of the sizeof operator.
http://pubs.opengroup.org/onlinepubs/009604499/basedefs/stddef.h.html
但是根据这个页面,size_t 的最大限制是 65535。
(其他整数类型的节限制):
size_t 的限制:SIZE_MAX 65535 http://pubs.opengroup.org/onlinepubs/007904975/basedefs/stdint.h.html
这是否意味着当我想遵守 C 标准时,我不能分配超过 65535 个字节?
【问题讨论】:
-
size_t必须能够表示sizeof可能返回的任何内容。 32 位系统上的sizeof(int[(unsigned) -1])是什么?在 64 位系统上?