View Single Post
Old 21 September 2021, 09:12   #3
Steady
Registered User
 
Join Date: May 2021
Location: Melbourne, Australia
Posts: 40
You are actually creating a myStruct variable in the header file which then is included in both c files. This causes your error.

Define in the .h file:

struct myStruct
{
int a;
int b;
};



If you want it to be global, in ONE of your .c files add:
struct myStruct myStruct;

In the other .c file, add:
extern struct myStruct myStruct;


It would be better not to use a global across .c files if you can help it, and just pass a pointer to myStruct in to the called functions as needed. Also, it would be better to use a different name from the actual structure type. (i.e. don't call both the structure and variable myStruct).
Steady is offline  
 
Page generated in 0.06212 seconds with 11 queries