数组大小(?) [英] array size (?)

查看:69
本文介绍了数组大小(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i我在我的电脑上使用redhat linux运行一个非常大的代码。

当我尝试增加我的数组大小,编译和运行,我得到

分段错误。我进入调试器,运行它,它立即崩溃

。我甚至无法追踪它发生的地方。

我不知道这是什么问题。任何想法???

解决方案

tw *********@yahoo.com (迈克)写道:

我正在使用redhat linux在我的电脑上运行一个非常大的代码。当我尝试增加我的数组大小,编译并运行时,我得到分段错误。我进入调试器,运行它,它立即崩溃。我甚至无法追踪它发生的地方。
我不知道是什么问题。任何想法???




你可能搞砸了内存分配或访问。尝试一下

内存调试器,比如valgrind。

-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\\ \\ b $ \\ n \\ b \ n",* q =" kl BIcNBFr.NKEzjwCIxNJC"; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \

);}返回0;}




" mike" < TW ********* @ yahoo.com>在消息中写道

news:58 ************************** @ posting.google.c om ...



我正在使用redhat linux在我的电脑上运行一个非常大的代码。
当我尝试增加我的数组大小,编译并运行时,我得到
分段错误。我进入调试器,运行它,它立即崩溃。我甚至无法追踪它发生的地方。
我不知道是什么问题。任何想法???




如果你无法追踪,你可能已经使用具有自动存储持续时间的阵列损坏了你的堆栈

这太大了。


阵列的大小是多少?在c89下,可以创建的最大对象

的大小为32767字节,c99下为65535字节。


-

j


在''comp.lang.c''中, tw*********@yahoo.com (迈克)写道:



我正在经营一个非常在我的电脑上使用redhat linux的大代码。
当我尝试增加我的数组大小,编译和运行时,我得到分段错误。我进入调试器,运行它,它立即崩溃。我甚至无法追踪它发生的地方。
我不知道是什么问题。任何想法???




我猜它是一个本地数组。有时候是这样的。 C语言并不清楚

局部变量的大小限制。听起来是一个实现问题。


天真的方式:在数组定义之前添加''static'。

更好的方法:使用动态分配(malloc()/ free())


-

-ed-在这里收到我的电子邮件: http://marreduspam.com/ad672570

C语言常见问题解答: http://www.eskimo.com/~scs/C-faq/top.html

C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99

FAQ de fclc: http://www.isty-info.uvsq.fr/~rumeau/fclc/


hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can''t even trace where it happens.
i have no idea what is the problem. any idea ???

解决方案

tw*********@yahoo.com (mike) writes:

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can''t even trace where it happens.
i have no idea what is the problem. any idea ???



You probably screwed up memory allocation or access. Try a
memory debugger like valgrind.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}



"mike" <tw*********@yahoo.com> wrote in message
news:58**************************@posting.google.c om...

hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can''t even trace where it happens.
i have no idea what is the problem. any idea ???



If you are unable to trace, you have probably corrupted your stack
by using an array with automatic storage duration that is too large.

What is the size of your array? Under c89 the size of the largest object
that can be created is 32767 bytes and 65535 bytes under c99.

--
j


In ''comp.lang.c'', tw*********@yahoo.com (mike) wrote:

hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can''t even trace where it happens.
i have no idea what is the problem. any idea ???



I guess it''s a local array. This happens. The C language isn''t clear about
local variables size limitations. Sounds to be an implementation issue.

The naive way : add ''static'' before the definition of the array.
The better way : use dynamic allocation (malloc() / free())

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/


这篇关于数组大小(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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