I have a very simple question. If I have a source code file like this:
#include<stdio.h>
#include"example.h"
struct mystructure{
//Data Variables
int a;
};
int main(){
mystructure somename;
somename.a = 1;
printf("%d\n", somename.a);
return 0;
}
With a header file like this:
#ifndef EXAMPLE_HEADER_H
#define EXAMPLE_HEADER_H
// Opaque declaration.
struct mystructure;
typedef struct mystructure mystructure;
#endif
The code will compile fine. I could also define the structure in the header file and it will compile fine.
However, if I define the structure in a different source code file and attempt to compile it with the main source code file it will keep throwing errors about forward declarations.
Is there a way to define a structure in a source code file give it a typedef in a header file and use it elsewhere in other source files?
I have been doing this awhile now by defining the structure in the header file, but I would like to know how to do this in a more opaque way.