Why can't we declare a static variable within a structure in the C programming language?

In C++, a struct is basically a class with all members public, so a static variable makes good sense there.

In C, a struct is a contiguous chunk of memory with fields. A static variable can not be created without changing that (as to implement a static you need to refer to a single memory location from all structs of that type), and that would be a big difference in complexity without much benefit.


Because C is not C++.

Because the C standard does not permit it.

Because it has no meaningful interpretation in C.

Tags:

C