Reputation: 79
I would like to have a struct that functions like this:
struct
member 1 (every instance of the struct has its own value of this)
static member (every struct shares this member)
I am aware that the static keyword does not do this. My question is, how can I mimic this behavior?
Could I create a member that is pointer to a global variable?
Is there some other better way to do this?
Upvotes: 1
Views: 952
Reputation: 223872
Unlike structs in C++ which can have static data members, C structs don't have such a construct.
Since this is a common value for anyone that may use it, just declare it as a global:
int my_struct_common_val = 42;
struct my_struct {
...
};
Upvotes: 3