gpt4 book ai didi

c - 错误 : expected declaration specifiers or ‘...’ before ‘list_node’

转载 作者:太空狗 更新时间:2023-10-29 17:11:33 24 4
gpt4 key购买 nike

我有一个 catalog.h 文件

typedef struct node* list_node;
struct node
{
operationdesc op_ptr;
list_node next;
};

还有一个parser.h

#include "catalog.h"

int parse_query(char *input, list_node operation_list);

两个 header 都有#ifndef#define#endif。编译器给我这个错误:expected declaration specifiers or ‘...’ before ‘list_node’ on the parse_query line。怎么了?我尝试将 typedef 放在 parser.h 中,没问题。当 typedef 在 catalog.h 中时,为什么会出现此错误?

最佳答案

错误是这样的(来自您的评论):

I had an #include "parser.h" in the catalog.h. I removed it, and now it compiles normally...

假设 #include "parser.h"catalog.h 中的 typedef 之前,并且您有一个包含 catalog.hparser.h 之前,然后在编译器包含 parser.h 时,typedef 尚不可用。 最好重新排列头文件的内容,这样您就不会产生循环依赖。

如果这不是一个选项,您可以确保包含这两个文件的任何源文件首先(或仅)包含 parser.h

关于c - 错误 : expected declaration specifiers or ‘...’ before ‘list_node’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5001346/

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