Re: [Q] Maximum Array size
持田@NETside です。
NetBSD/i386 での様子です。参考までに。
% uname -srm
NetBSD 1.6P i386
% cc -v
Reading specs from /usr/pkg/gcc3/lib/gcc-lib/i386--netbsdelf/3.3/specs
Configured with: ./configure --prefix=/usr/pkg/gcc3 --host=i386--netbsdelf --enable-shared --enable-languages=c
Thread model: single
gcc version 3.3
% cc -DARLEN=1000000 -Wall -o a a.c
% ./a
55, G
% cc -DARLEN=8012998 -Wall -o a a.c
% ./a
zsh: cannot allocate memory: ./a
% cc -DARLEN=8012999 -Wall -o a a.c
a.c:13: error: size of variable `pkt' is too large
% echo '268 * 8012998' | bc
2147483464
% echo '268 * 8012999' | bc
2147483732
% echo '2^31' | bc
2147483648
% cat a.c
#include <stdio.h>
#ifndef ARLEN
#define ARLEN 1000000
#endif
struct packet {
int nodenumber;
int destination;
int source;
char body [ 256 ];
} pkt[ARLEN];
int main()
{
pkt[0].nodenumber = 55;
pkt[ARLEN -1].body[255] = 'G';
printf("%d, %c\n", pkt[0].nodenumber, pkt[ARLEN -1].body[255]);
return 0;
}
--
持田 修司 NETside Technologies Inc.
-- Equal Opportunity for All Good Architectures, NetBSD. --
Fnews-brouse 1.9(20180406) -- by Mizuno, MWE <mwe@ccsf.jp>
GnuPG Key ID = ECC8A735
GnuPG Key fingerprint = 9BE6 B9E9 55A5 A499 CD51 946E 9BDC 7870 ECC8 A735