Static Var in Struct....

R

Raxit

Can A C Program having static Variable in Structure is possible.....

i.e.

struct A
{
int a;
static int b;
};

if yes then how to access this static variable.....

As we done in C++ with A::b{i.e. using Scope Resolution}
 
J

Jack Klein

Can A C Program having static Variable in Structure is possible.....
No.

i.e.

struct A
{
int a;
static int b;

The members of a structure can't have storage class specifiers.
Objects of the structure type can, but they apply to all of the
members.
 
R

Raxit

I want to know...the logical Reason Why not allowing Structure has
Static Member....

Raxit
 
C

CBFalconer

Raxit said:
I want to know...the logical Reason Why not allowing Structure has
Static Member....

Are you asking this again because you didn't like Jacks answer, and
is that why you didn't bother to quote anything from his answer?
Is there any connection with the strange and annoying sentence
construction you use? Surely by now you have figured out how to
use Google, if not try my sig. below.
 
C

Chris Dollin

Raxit said:
I want to know...the logical Reason Why not allowing Structure has
Static Member....

What counts as a logical reason?

Here's a possible reason: in C, there's little advantage to be
gained by allowing it. (Just declare a Plain Old Static Variable.)

You might say "But I want the name to hide in the struct namespace!".

I say back, "Dude, if you want namespacey things in C, there are
things you could do with *lots* more payback than static structure
members."
 
G

Grumble

CBFalconer said:
Are you asking this again because you didn't like Jacks answer, and
is that why you didn't bother to quote anything from his answer?
Is there any connection with the strange and annoying sentence
construction you use?

He is posting from India (NNTP-Posting-Host: 202.149.200.69).
Perhaps English is not his mother tongue?

AFAICT, he's asking for a rationale.
 
C

CBFalconer

Grumble said:
He is posting from India (NNTP-Posting-Host: 202.149.200.69).
Perhaps English is not his mother tongue?

AFAICT, he's asking for a rationale.

Maybe I am made over grouchy by the foolish use of the broken
google interface, and the total lack of quotations. Especially
when it is unnecessary and I and others have been campaigning to
show how to beat it.

To answer him, a structure is a single entity, to be stored
somewhere. Static specifies the class of storage involved. It is
not feasible to store one portion one place and another elsewhere
and maintain the ability to handle it as a unit.
 
T

Tor Rustad

Raxit said:
I want to know...the logical Reason Why not allowing
Structure has Static Member....

Well, if that wasn't there from the beginning, the logical
reason should rather be given the other way around:

1. Why introduce static struct member?
2. Will it break existing code?


BTW. I have no idea what "static struct member" is
in C++. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top