C - override error in Xcode

My c headers file contains the following error message in Xcode

Redefinition of 'entry'


But it works fine when I compile it using gcc

the command line. Can any of you provide an explanation why?

This 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;



This is snapshot.c:

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "snapshot.h"

main(int argc, char *argv[]){
    int x = 7;
    printf("x= %d\n" , x);
    printf("value = %d\n", 1);
    return 0;



source to share

1 answer


was originally reserved as a keyword and then deprecated. Therefore older compilers do not allow (see this question ). Change the name of the structure and you should be fine.



All Articles