Small modification in your program
Quote:
Originally Posted by
Bayint Naung
Code:
abc.h
struct STRUCT_ABC {
int a;
};
abc.c
#include "abc.h"
void abc(struct STRUCT_ABC *a)
{
}
def.c
struct STRUCT_ABC {
char *s;
double x;
};
void def(struct STRUCT_ABC *a) // if you export def() function,
problem since compile will use struct STRUCT_ABC defined in abc.h
{
}
main.c
#include "abc.h" //include struct def
int main(void)
{
struct STRUCT_ABC foo;
def(&foo); // problem!!
abc(&foo); // OK
return 0;
}
You can not export any function defined in def.c that needs struct STRUCT_ABC. (i.e functions that take STRUCT_ABC as para or return STRUCT_ABC).
What if flow goes as below:
def.c
struct STRUCT_ABC {
char *s;
double x;
};
void def() // Fine
{
struct STRUCT_ABC foo;
<local usage of foo valid here>
<return to main>
}
int main(void)
{
struct STRUCT_ABC foo;
abc(&foo); // OK
def(); //def called after abc
return 0;
}
This is the actual replica of code which i'm working currently with. abc.c & header file same as the way what you coded.
Additionally control goes in def after abc.
Also, in my case not necessary that both the functions will be called from same common function. Only common thing is that both come in the same flow.