在C中创建和访问非常大的数组 [英] Creating and Accessing Very Big Arrays in C

查看:59
本文介绍了在C中创建和访问非常大的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用GCC。请问您能告诉我,我可以用C创建的最大数量的

数组元素是什么,即


char * anArray =(char *) calloc(?? MAX ??,sizeof(char));


我设法使用DOUBLE数据类型创建数组,但当我尝试

。为了访问数组,编译器抱怨这个数字不是一个

INT,即


//这个成功

char * anArray =(char *)calloc(999999999999999999,sizeof(char));


//这不能编译,因为数字1234567891234584不是

INT

anArray [1234567891234584] = 1;


我们非常感谢您的帮助和建议。


感谢你的期待,


Daniel

解决方案

dj ***** @ gmail.com 写道:





我是usi ng GCC。请问您能告诉我,我可以用C创建的最大数量的

数组元素是什么,即


char * anArray =(char *) calloc(?? MAX ??,sizeof(char));



取决于你的系统。


我已经设法使用DOUBLE数据类型创建数组,但是当我尝试使用
来访问数组时,编译器会抱怨该数字不是

INT, ie



应该是''int''?


//这成功了

char * anArray =(char *)calloc(999999999999999999,sizeof(char));



真的吗?


//这不能编译,因为数字1234567891234584不是

INT

anArray [1234567891234584] = 1;


如果你可以分配超过INT_MAX元素,你可能应该

写1234567891234584LL告诉编译器常量是长的
长,否则它将默认为int。


-

Ian Collins。


Ian Collins写道:

dj ***** @ gmail.com 写道:


//这不能编译因为号码1234567891234584不是一个

INT

anArray [1234567891234584] = 1;



如果你可以分配超过INT_MAX的元素,你可能应该用b
写1234567891234584LL告诉编译器常量是长的
long,否则默认为int。



常量总是采用可以代表它们的类型

(除非没有这种类型)。在这种情况下,常数

将很长,而不必指定它 -

假设数字超过LONG_MAX,并且

编译器处于C99模式。


我不知道这个神话来自哪里

无后缀常量有问题。


Old Wolf写道:


Ian Collins写道:


>> dj ***** @ gmail.com写道:


>>> //这不编译,因为数字1234567891234584不是
INT
anArray [1234567891234584] = 1;


如果你可以分配超过INT_MAX元素,你应该可能会写1234567891234584LL告诉编译器常量是长的长,否则会默认为int。




常量总是采用可以代表它们的类型

(除非没有这种类型)。在这种情况下,常数

将很长,而不必指定它 -

假设数字超过LONG_MAX,并且

编译器处于C99模式。


我不知道这个神话来自哪里

无后缀常量有问题。



在我的情况下,昏暗而遥远的过去!


干杯,


-

Ian Collins。


Hi,

I''m using GCC. Please could you tell me, what is the maximum number of
array elements that I can create in C, i.e.

char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ;

I''ve managed to create arrays using DOUBLE data types, but when I try
to access the array, the compiler complains that the number is not an
INT, i.e.

// this succeeds
char* anArray = (char*) calloc( 999999999999999999 , sizeof(char) ) ;

// this does not compile because the number 1234567891234584 is not an
INT
anArray[1234567891234584] = 1 ;

Your help and advice would be sinceraly appreciated.

Thanking you in anticipation,

Daniel

解决方案

dj*****@gmail.com wrote:

Hi,

I''m using GCC. Please could you tell me, what is the maximum number of
array elements that I can create in C, i.e.

char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ;

Depends on your system.

I''ve managed to create arrays using DOUBLE data types, but when I try
to access the array, the compiler complains that the number is not an
INT, i.e.

Should that be ''int''?

// this succeeds
char* anArray = (char*) calloc( 999999999999999999 , sizeof(char) ) ;

Realy?

// this does not compile because the number 1234567891234584 is not an
INT
anArray[1234567891234584] = 1 ;

If you can allocate more than INT_MAX elements, you should probably
write 1234567891234584LL to tell the compiler the constant is a long
long, otherwise it will default to int.

--
Ian Collins.


Ian Collins wrote:

dj*****@gmail.com wrote:

// this does not compile because the number 1234567891234584 is not an
INT
anArray[1234567891234584] = 1 ;

If you can allocate more than INT_MAX elements, you should probably
write 1234567891234584LL to tell the compiler the constant is a long
long, otherwise it will default to int.

Constants always take on a type that can represent them
(unless there is no such type). In this case, the constant
will be a long long without you having to specify it --
assuming that the number exceeds LONG_MAX, and that
the compiler is in C99 mode.

I don''t know where this myth came from that there is
something wrong with un-suffixed constants.


Old Wolf wrote:

Ian Collins wrote:

>>dj*****@gmail.com wrote:

>>>// this does not compile because the number 1234567891234584 is not an
INT
anArray[1234567891234584] = 1 ;


If you can allocate more than INT_MAX elements, you should probably
write 1234567891234584LL to tell the compiler the constant is a long
long, otherwise it will default to int.



Constants always take on a type that can represent them
(unless there is no such type). In this case, the constant
will be a long long without you having to specify it --
assuming that the number exceeds LONG_MAX, and that
the compiler is in C99 mode.

I don''t know where this myth came from that there is
something wrong with un-suffixed constants.

In my case, the dim and distant past!

Cheers,

--
Ian Collins.


这篇关于在C中创建和访问非常大的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆