tags:

views:

99

answers:

2

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

+4  A: 

Because C is not C++.

Because the C standard does not permit it.

Because it has no meaningful interpretation in C.

Jonathan Leffler
(zing)­­­­­­­­­
Delan Azabani
+4  A: 

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.

MaxVT
@MaxVT: I knew this ....!!! Is this the only reason ?
Jagan
I'd sy this is a pretty strong reason.
delnan