Reputation: 7034
I have a common header file for multiple source files in a C project. I want a certain struct instance:
typedef struct
{
char username[255];
char password[255];
} Configuration;
Configuration config;
To be available for all source files, and any changes made to it in any of the source files, should affect all others. How is this possible?
Upvotes: 0
Views: 1206
Reputation: 229342
In your header file you declare the config variable as extern:
extern Configuration config;
And in one, and only one, source file you define that variable like so:
Configuration config;
Upvotes: 5