gpt4 book ai didi

C 创建超过一定大小的结构数组会导致崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 00:44:34 25 4
gpt4 key购买 nike

<分区>

大家好,我是 C 语言的新手(本周才开始接触),我想确保我没有看错兔子的家,并希望能找到正确的兔子洞。

我创建了一个结构:

#define MAX 64
#define ARRAY_SIZE 2048

struct object {
int q, c, p;
char name[MAX]; //Stores string up to 63 characters
char arr[ARRAY_SIZE][MAX]; // Creates an array of 2048 cells with string of length 63 max
};

int main(){
...
...
int variable = 30;
struct object l[variable]; //This is where the crash happens. But only when either variable is too large (for instance works on 15 just fine, but anything over 20 it crashes), or when Array_SIZE is too larger, for instance works fine with 1024 but 2048 crashes.
...
...
}

我遇到的崩溃错误如下:进程在 cmd 窗口中返回 -1073741571 (0xC00000FD)。以及 IDE 中调试器中的以下内容:程序收到信号 SIGSEGV,段错误。[下级 1(进程 12120)退出,代码为 030000000375]

我声明结构数组的方式是否明显有误?为什么大数字不起作用而小数字起作用?

上述错误是否表明我正在某处越界访问某些内容?我一直在修改代码,但似乎找不到任何原因说明为什么较大的数字不起作用而较小的数字起作用。我的内存占用量似乎不是问题,只是几兆内存。

我需要帮助寻找什么(我找不到任何越界访问的实例,所以我觉得我没有在追逐正确的兔子,需要寻找其他东西)?或者我可能在不知情的情况下为 C 做了一些非法的事情?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com