Lets say I have a header file foo.h which declares a struct variable
#include <stdio.h>
typedef struct foo_struct foo_s;
foo_s foo_function(int a);
foo_s bar_function(int b);
and a source file foo.c which actually defines the structure
#include "foo.h"
struct foo_struct
{
int a;
int b;
};
foo_s foo_function(int a)
{
foo_s fs;
fs.a = a;
return fs;
}
Now I want to access the structure defined in foo.c in another source file bar.c so I try the following:
#include "foo.h"
foo_s bar_function(int b)
{
foo_s fb;
fb.b = b;
return fb;
}
...and fail with bar.c:3:7: error: return type is an incomplete type
I sort of understand what the problem is but is there a workaround?