gpt4 book ai didi

c - 仅在一个函数中出现 "variable_name"未声明错误

转载 作者:行者123 更新时间:2023-11-30 21:19:25 28 4
gpt4 key购买 nike

我在尝试诊断代码中的错误时遇到了一些麻烦。由于某种原因,编译器认为我在声明它的地方有一个未声明的变量。我找不到解决方案。

struct node {
int size_chunk_memory;
//1 = free, 0= used
int is_free;
struct node *next;
struct node *prev;
};

void merge(void* address) {
if (address == 0) {
return;
}
struct node* curr_merge = (struct node*)address;
struct node* prev_merge = curr_merge->prev;
struct node* next_merge = curr_merge->next;

if (curr_merge->is_free == 1 && prev_merge->is_free == 1) {
prev_merge->size_chunk_memory = size_chunk_memory + curr_merge->size_chunk_memory + sizeof(struct node);
prev_merge->next = curr_merge->next;
curr_merge = prev_merge;
}
if (curr_merge->is_free == 1 && next_merge->is_free == 1) {
curr_merge->size_chunk_memory = size_chunk_memory + next_merge->size_chunk_memory + sizeof(struct node);
curr_merge->next = next_merge->next;
}
}

这是我收到的错误:

 ‘size_chunk_memory’ undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)

由于篇幅原因,我省略了很多程序。如果您需要更多信息,请告诉我。

非常感谢。

最佳答案

prev_merge->size_chunk_memory = size_chunk_memory + curr_merge->size_chunk_memory + sizeof(struct node);

curr_merge->size_chunk_memory = size_chunk_memory + next_merge->size_chunk_memory + sizeof(结构节点);

您可以在结构引用之外访问它。您需要以与 size_chunk_memory 的其他用途相同的方式访问它,即通过 struct node 指针和 ->

关于c - 仅在一个函数中出现 "variable_name"未声明错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49523444/

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