我正在尝试将 3rd 方库包含到.c文件中,但它会给出重新定义或冲突类型错误,因为它具有同名的 typedef 结构。
在阅读了 SO 中的一些答案后,我尝试包含警卫,显然直接更改.h文件上的 typedef 已经解决了这个问题。
例如(还必须更改函数返回类型)
// stack.h
typedef struct item stack_item;
// queue.h
typedef struct item queue_item;
但是,原始代码如下:
// stack.h
typedef struct item item;
// queue.h
typedef struct item item;
它抛出以下错误:
In file included from test.c:5:0:
Queues/queue.c:6:8: error: redefinition of ‘struct item’
struct item {
^
In file included from Stacks/stack.c:4:0, from test.c:4:
Stacks/stack.h:6:16: note: originally defined here
typedef struct item item;
^
我想知道解决此问题的标准方法是什么,而不是更改.h文件中的定义