【问题标题】:C - redefinition error in XcodeC - Xcode中的重新定义错误
【发布时间】:2015-04-29 06:34:18
【问题描述】:

我的 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

这是快照.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;
}

【问题讨论】:

  • 这是 complete 错误吗?请编辑您的问题以包含竞争和未经编辑的错误输出。
  • 是的。那是完全的错误。 @Benjy 的回答很好地解决了这个问题。也感谢保罗的评论。

标签: c xcode header-files redefinition


【解决方案1】:

entry 最初保留为关键字,后来被宣布为过时。所以旧的编译器不允许它(见this question)。更改结构的名称,一切都应该没问题。

【讨论】:

  • 另外编译例如-std=c99 可以解决这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
相关资源
最近更新 更多