I have a question about the member variables of static struct in C language.
Someone said we can declare a static struct, but in C, struct do not have the static members like class in C++, what does this mean? If I declare a static struct, what is the status of the members variable? can some one help me on this?
Note that a static struct itself is different from a static member of a struct. While you can declare a static struct variable:
you can’t define a struct type with a static member:
The reason for this is that in C, a struct is a type – declaring a type of which a member variable is always the same instance (i. e. static) for multiple instances of that type is simply nonsense. In C++, structs are in reality classes (they only differ in the default visibility scope of members), and in C++ the static keyword means something else in this case. It means a class method – but since C doesn’t have classes and methods, this doesn’t make sense and is invalid in C.
Lesson learned: C++ is not C.