Two problems with your code:
1) use include guards in headers
2) do not define variables in header files, this way each *.c file which includes your header will get its own copy of the variable
to solve 2), use the "extern" specifier
apart from that, your example seems to compile just fine on gcc 4.5:
// this code is wrong, correct it by applying 1) and 2)
//
//
// file1.h
typedef struct {
int i;
} struct_1;
#define size_1 10
#define DATA_LEN (size_1 + sizeof(struct_1) )
//file2.h
#include "file1.h"
char text_data[ DATA_LEN ];
//main.c
#include "file2.h"
int main(){
return 0;
}
// compiled ok with :
// gcc main.c -Werror -Wall -pedantic
// this code is wrong, correct it by applying 1) and 2)
//
//
// file1.h
typedef struct {
int i;
} struct_1;
#define size_1 10
#define DATA_LEN (size_1 + sizeof(struct_1) )
//file2.h
#include "file1.h"
char text_data[ DATA_LEN ];
//main.c
#include "file2.h"
int main(){
return 0;
}
// compiled ok with :
// gcc main.c -Werror -Wall -pedantic
To copy to clipboard, switch view to plain text mode
Bookmarks