【发布时间】:2021-12-30 09:15:55
【问题描述】:
话虽如此,我已经尝试解决网上冲浪的问题,并且我发现了一些与我的问题非常相似的问题,但尽管如此,我没有找到任何解决方案。 我想知道是否有人可以帮助我解决这个问题,解释什么不起作用,而不是将我重定向到另一个博客。
代码如下:
1)文件:list.h
#include "list.c"
#include "element.h"
typedef struct list_element {
element value;
struct list_element* next;
} item;
typedef item* list;
list emptyList(void);
boolean empty(list);
element head(list);
list tail(list);
list cons(element, list);
.......
- 文件列表.c
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
list emptyList(void) {
return NULL;
}
boolean empty(list l) {
if (l == NULL)
return true;
else
return false;
}
list tail(list l) {
if (empty(l))
return NULL;
else
return l->next;
}
....
3)文件元素.h
#include "element.c"
#ifndef ELEMENT_H
#define ELEMENT_H
typedef int element;
typedef enum { false, true } boolean;
boolean isLess(element, element);
boolean isEqual(element, element);
element getElement(void);
void printElement(element);
- 文件 element.c
#include "element.h"
#include <stdio.h>
boolean isEqual(element e1, element e2) {
return (e1 == e2);
}
boolean isLess(element e1, element e2) {
return (e1 < e2);
}
element getElement() {
element el;
scanf(" %d", &el);
return el;
}
void printElement(element el) {
printf(" % d", el);
}
然后编译器给了我错误代码:
E0003(file #include /../../../../../../element.h includes itself)
和错误
code C1014 (too many file of inclusion, depth=1024) for file list.c and element.c```
So I've tried to use the guards (surely in the wrong way) and the error list was almost the same.
I would be grateful if someone could help me out
thank you for the attention.
【问题讨论】:
-
从不包含
.c文件 -
永远不要包含
.c文件。 (好吧,直到你开始认为自己是一个完全了解后果的高级程序员) -
@EugeneSh。如果我不将它们包含在 header.h 中,我如何使用 list.c 和 element.c 的函数
-
@ric - 您不要在 .h 文件中使用它们。不要在 .h 文件中添加任何代码或数据
-
有一个非常简单的方法来考虑
#include。它只是获取文件并粘贴其内容。如果你这样想,你就会避免这样的混乱。因此,您可以将您的项目视为仅包含.c文件并粘贴了标题。
标签: c list header include guard