[英]C - redefinition error in Xcode
我的c头文件在Xcode中有以下错误消息
Redefinition of 'entry'
但是当我在命令行中使用gcc
编译它时它工作得很好。 你们中的任何人都可以解释原因吗?
这是snapshot.h
:
#ifndef SNAPSHOT_H
#define SNAPSHOT_H
#define MAX_KEY_LENGTH 16
#define MAX_LINE_LENGTH 1024
typedef struct value value;
typedef struct entry entry;
typedef struct snapshot snapshot;
struct value {
value* prev;
value* next;
int value;
};
// the line below is where the redefinition error appears
struct entry {
entry* prev;
entry* next;
value* values;
char key[MAX_KEY_LENGTH];
};
struct snapshot {
snapshot* prev;
snapshot* next;
entry* entries;
int id;
};
#endif
这是snapshot.c:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "snapshot.h"
int
main(int argc, char *argv[]){
int x = 7;
printf("x= %d\n" , x);
printf("value = %d\n", 1);
return 0;
}
entry
最初保留为关键字,后来声明为过时。 所以较旧的编译器不允许它(参见这个问题 )。 更改结构的名称,一切都应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.