私の IDE はC-free 5.0で、コンパイラはMinGWです。
「list.h」、「list.c」の 2 つのファイルがあります。
list.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
list.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;
}
このファイルをコンパイルしようとすると、エラーが発生しました
"list.c:5: redefinition of 'struct node'"
次に、すべての「 node」を「Node 」に置き換えると、驚くべきことが起こりました! コンパイルOK!私は本当にこれを理解できません。これは C ライブラリに関連している可能性がありますか?