You can define the structure in each source file, then declare the instance variable once as global and once as extern:
// File1.c struct test_st { int state; int status; }; struct test_st g_test; // File2.c struct test_st { int state; int status; }; extern struct test_st g_test;
Then the linker will do the magic, and the source file will point to the same variable.
However, duplicating a definition in multiple source files is a bad coding practice, because in case of changes you need to manually change each definition.
A simple solution is to put the definition in the header file and then include it in the entire source file that uses the structure. To access a single instance of the structure in the source files, you can still use the extern method.
// Definition.h struct test_st { int state; int status; }; // File1.c
source share