Hi, I got this warning message when compiling a project under MinGW using gcc. Now, to simplify, I'll try to give an example:
There are 3 files included in this problem, which belong to a large project:
1) a.h
2) b.h
3) test.c
a.h:
Code:
#ifndef A_H
#define A_H
#include "b.h"
struct A
{
int a;
int b;
};
void a_func(struct A *a, struct B *b);
#endif
As you can see, it declares a function named `a_func', which accepts a pointer to `struct A', and a pointer to `struct B' (so I included `b.h'). `a_func' might be defined in `a.c' and used elsewhere, which is not the problem.
b.h:
Code:
#ifndef B_H
#define B_H
#include "a.h"
struct B
{
double i;
double j;
struct A *a;
};
#endif
`struct B' contains a pointer to `struct A', so I included `a.h'.
and test.c:
Code:
#include <stdio.h>
#include "b.h"
int main(void)
{
struct B b;
b.i = 2.71;
b.j = 3.14;
printf("i is %f and j is %f\n", b.i, b.j);
return 0;
}
Now compile test.c:
Code:
gcc -Wall -c test.c
it says:
Code:
In file included from b.h:4,
from test.c:2:
a.h:12: warning: "struct B" declared inside parameter list
a.h:12: warning: its scope is only this definition or declaration, which is probably not what you want
***
Now I understand that it is because after we included `b.h' in `test.c', `B_H' has been defined, and since `b.h' includes `a.h' while `a.h' includes `b.h' also (then `b.h' is actually not included in `a.h' because `B_H' has already been defined), the definition of `struct B' is not known by `a.h'.
I also understand that, if i put `void a_func(struct A *a, struct B *b);' into `b.h', this problem is solved in this case, but this breaks the organization of this project since `a_func' is defined in `a.c', which is supposed to be with `a.h'.
So if anyone has any idea to keep the declaration of `a_func' in `a.h' and meanwhile avoid the `struct declared inside parameter list' problem, I'll be very grateful.