简体   繁体   English

C - Xcode中的重定义错误

[英]C - redefinition error in Xcode

My c header file has the following error message in Xcode 我的c头文件在Xcode中有以下错误消息

Redefinition of 'entry'

But it works perfectly when I compile it using gcc in command line. 但是当我在命令行中使用gcc编译它时它工作得很好。 Could any of you give an explanation of why? 你们中的任何人都可以解释原因吗?

This is snapshot.h : 这是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

This is snapshot.c: 这是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 was originally reserved as a keyword and then later declared obsolete. entry最初保留为关键字,后来声明为过时。 So older compilers don't allow it (see this question ). 所以较旧的编译器不允许它(参见这个问题 )。 Change the name of the struct and everything should be fine. 更改结构的名称,一切都应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM