-
typedef problem
Hello, I have 3 header files and 1 .c file.
The .c file #includes both header files.
In the 2 header files, there are extern definitions of of a struct:
header1.h:
Code:
#include "types.h"
extern struct a
{
mytype a;
....
} myStructA;
header2.h:
Code:
#include "types.h"
extern struct b
{
mytype b;
.....
} myStructB
types.h
Code:
typedef int mytype;
mycfile.c
Code:
#include "header1.h"
#include "header2.h"
struct myStructA;
struct myStructB;
int main()
{
....
}
My issue is that gcc keeps complaining about a redefinition of typedef mytype. I understand what this means since I #include types.h in both headers. I need to do this since both headers use mytype in their stucts. Is there any way around this?
-
-
if it is microsoft, you can use
#pragma once
-
That pragma does not work very well for inclusion guards.
And the struct shouldn't be "extern" either. It's a declaration.