Re: Why connot declare a static member of STRUCT or UNION?
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Tue, 23 Oct 2007 21:51:22 -0500
On Tue, 23 Oct 2007 22:31:45 +0530, santosh <santosh.k83@xxxxxxxxx>
wrote in comp.lang.c:
James Kuyper Jr. wrote:
Richard wrote:
It would make perfect sense to see static in a struct as far as I can
see. What is so nonsensical about it? Or is your point not that it
wouldn't make sense, but that it's simply not available?
The standard defines (at least) three different meanings for the
keyword static, depending upon whether it's at file scope, block
scope, or function prototype scope. A single struct type, once
defined, could be used to declare an object in any of those scopes, so
the possible meaning of the 'static' keyword when applied to a member
would have to change with the scope.
File scope: what would it mean for a structure object to have external
linkage, but a member of that object to have internal linkage (or vice
versa)?
Presumably that the static member is invisible to other modules?
Horse apples. Nothing in a structure is accessible from other
translation units (other than as an array of unsigned chars) unless
the struct definition is visible. The identical struct definition,
with the same types in the same order having the same names.
Block scope: What would it mean for a structure object to be
automatically or dynamically allocated, and to have a member that was
statically allocated (or vice versa)?
Presumably that the static member retains it's previous value?
All members in a struct object are "static" throughout its lifetime.
As long as the object exists, each member retains its last stored
value until such time as it is assigned another value.
But once an automatic instance of the struct goes out of scope, or a
dynamically allocated instance is free()'d, the object ceases to exist
and there is no way it can retain a previous value.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- References:
- Why connot declare a static member of STRUCT or UNION?
- From: arkmancn
- Re: Why connot declare a static member of STRUCT or UNION?
- From: James Kuyper Jr.
- Re: Why connot declare a static member of STRUCT or UNION?
- From: Richard
- Re: Why connot declare a static member of STRUCT or UNION?
- From: James Kuyper Jr.
- Re: Why connot declare a static member of STRUCT or UNION?
- From: santosh
- Why connot declare a static member of STRUCT or UNION?
- Prev by Date: Re: Print a short instead of an int... ? What's up with "%hd"?
- Next by Date: Re: Has ANSI Approved ISO/IEC 9899:1999?
- Previous by thread: Re: Why connot declare a static member of STRUCT or UNION?
- Next by thread: earn money with faith
- Index(es):
Relevant Pages
|