C “关于错误的困惑”;“结构的重新定义”;
我的IDE是,编译器是 我有两个文件:'list.h','list.c' 清单h:C “关于错误的困惑”;“结构的重新定义”;,c,struct,case-sensitive,redefinition,C,Struct,Case Sensitive,Redefinition,我的IDE是,编译器是 我有两个文件:'list.h','list.c' 清单h: typedef int elementType; #ifndef _LIST_H #define _LIST_H struct node; typedef struct node* ptrToNode; typedef ptrToNode list; typedef ptrToNode position; list makeEmpty(list l); #endif typedef int eleme
typedef int elementType;
#ifndef _LIST_H
#define _LIST_H
struct node;
typedef struct node* ptrToNode;
typedef ptrToNode list;
typedef ptrToNode position;
list makeEmpty(list l);
#endif
typedef int elementType;
#ifndef _LIST_H
#define _LIST_H
typedef struct node{
elementType element;
struct node* next;
}*ptrToNode;
//typedef struct node* ptrToNode;
typedef ptrToNode list;
typedef ptrToNode position;
list makeEmpty(list l);
#endif
清单c:
#include <stdio.h>
#include "list.h"
#include <stdlib.h>
struct node{
elementType element;
position next;
};
list makeEmpty(list l){
if(l == NULL){
//delete list
}
l = malloc(sizeof(struct node));
if(l == NULL){
printf("fail to malloc memory");
exit(-1);
}
l->next = NULL;
return l;
}
然后我将所有的“节点”替换为“节点”,神奇的事情发生了!编译没问题!我真的不能理解这个。这可能与C库有关吗?关于struct和typedef的事情可能会很混乱,至少对我来说是这样。 因为结构在使用C++感知编译器时已经创建了一个类型,所以必须重新编制语句。将定义推入头中,而不是向前声明。
如果我没有弄错的话,就是这个“typedef struct node*ptrToNode;”创建了双重声明。这里有一些很好的文章讨论关于typedef和structs的主题。祝你好运我认为这都是编译器的依赖关系。它可以与VisualStudio配合使用。如果您不想将“node”重命名为“node”(我希望在MinGW定义了自己的节点之前,它可以正常工作),您可以通过以下方式尝试: 清单h:
typedef int elementType;
#ifndef _LIST_H
#define _LIST_H
struct node;
typedef struct node* ptrToNode;
typedef ptrToNode list;
typedef ptrToNode position;
list makeEmpty(list l);
#endif
typedef int elementType;
#ifndef _LIST_H
#define _LIST_H
typedef struct node{
elementType element;
struct node* next;
}*ptrToNode;
//typedef struct node* ptrToNode;
typedef ptrToNode list;
typedef ptrToNode position;
list makeEmpty(list l);
#endif
和你的名单
#include <stdio.h>
#include "poly.h"
#include <stdlib.h>
list makeEmpty(list l){
if(l == NULL){
//delete list
}
l = malloc(sizeof(struct node));
if(l == NULL){
printf("fail to malloc memory");
exit(-1);
}
l->next = NULL;
return l;
}
#包括
#包括“poly.h”
#包括
列表makeEmpty(列表l){
if(l==NULL){
//删除列表
}
l=malloc(sizeof(struct node));
if(l==NULL){
printf(“malloc内存失败”);
出口(-1);
}
l->next=NULL;
返回l;
}
不能在C中混合使用大小写,这不是Perl!拾取,它是全部节点
或全部节点
。没有魔法…对不起,我的提示导致了你的误解,我已经更正了上面的代码,这就是你编译的全部代码吗?我的MinGW编译得很好。这不重要——IDE(通常)不会编译,它是编译器的一部分。但是我使用命令行运行它,在我的例子中没有IDE。关于涉及任何其他代码,您的答案是什么?这绝对是我正在编译的所有代码。我再试一次,也会遇到同样的问题