【发布时间】:2015-07-09 20:20:19
【问题描述】:
我有以下 main.c 文件:
#include <stdio.h>
#include <stdlib.h>
#include <wctype.h>
#include "lista.h"
int main(int argc, char *argv[])
{
struct nod *root = NULL;
root = init(root);
return 0;
}
还有 lista.h:
#ifndef LISTA_H_INCLUDED
#define LISTA_H_INCLUDED
#include "lista.c"
typedef struct nod
{
int Value;
struct nod *Next;
}nod;
nod* init(nod *);
void printList(nod *);
#endif // LISTA_H_INCLUDED
最后是 lista.c,即:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include "lista.h"
nod* init(nod *root)
{
root = NULL;
return root;
}
void printList(nod *root)
{
//We don't want to change original root node!
nod *aux = root;
printf("\n=== Printed list =====\n");
while (aux != NULL)
{
printf(aux->Value);
aux = aux->Next;
}
puts("\n");
}
即使在包含头文件之后,我也会收到三个错误: 未知类型名称“点头”
如何使 lista.h 中的 typedef 可以在 lista.c 上看到?
我就是想不通这里发生了什么。
【问题讨论】:
-
从
lista.h中删除#include "lista.c"。在实际定义nod之前,它会引入所有lista.c内容(引用nod)。通常,.h文件从不包含.c。反之亦然。 -
原则上从不包含 C 文件。既不在标题中,也不在来源中。
标签: c data-structures typedef ansi-c