469,315 Members | 2,178 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

static structure

i am confused about static structure...

static struct
{
int a;

}st;

what is the difference between static structure and normal structure?
Jun 1 '07 #1
7 53353
Savage
1,764 Expert 1GB
i am confused about static structure...

static struct
{
int a;

}st;

what is the difference between static structure and normal structure?
If static keyword is applied to struct(or class),all of the members are static.

Savage
Jun 1 '07 #2
svlsr2000
181 Expert 100+
If static keyword is applied to struct(or class),all of the members are static.

Savage
hi savage,
is this c++ or java. I dont think there is something like static class in c++
please see this. I have not come across this in my compiler document.
:(
http://www.thescripts.com/forum/thread647427.html
Jun 1 '07 #3
i have to know about static struct in c-language..
Jun 1 '07 #4
when we declare static to a structure all the element will not become static...
because when varibales of structure are being re-intialized again...where as in static varibale will not reintialize .....

Then what is the use of declaring a structure as static?
Jun 1 '07 #5
Banfa
9,064 Expert Mod 8TB
If static keyword is applied to struct(or class),all of the members are static.
This isn't right.

It is not the structure that is declared static but the variable st. A variable declaration has the basic structure

[Storage Specifiers] [Type] [Variable Name];

This this case

Storage Specifiers
static

Type
struct
{
int a;

}

Variable Name
st

What the static keyword means is somewhat dependent on where this declaration appears in the rest of the code. Inside a function it indicates that the variable should not be put on the stack but in the data segment and is persistent while the function is not running. Outside a function it merely indicates that the variable is not accessable outside the file it is in.

So the static in your declaration means exactly the same as the static in this declaration

Expand|Select|Wrap|Line Numbers
  1. static int integer_variable;
  2.  
Jun 1 '07 #6
AdrianH
1,251 Expert 1GB
This isn't right.

It is not the structure that is declared static but the variable st. A variable declaration has the basic structure

[Storage Specifiers] [Type] [Variable Name];

This this case

Storage Specifiers
static

Type
struct
{
int a;

}

Variable Name
st

What the static keyword means is somewhat dependent on where this declaration appears in the rest of the code. Inside a function it indicates that the variable should not be put on the stack but in the data segment and is persistent while the function is not running. Outside a function it merely indicates that the variable is not accessable outside the file it is in.

So the static in your declaration means exactly the same as the static in this declaration

Expand|Select|Wrap|Line Numbers
  1. static int integer_variable;
  2.  
Thank you Ben, when I was reading all of the responses, I was about to scream. ;)

And just to clarify, the struct specified is what is called an anonymous struct. It is has no name.


Adrian
Jun 1 '07 #7
zidane
1
it's sure that we can write static struct on c program
that's a way to prohibit the user to access on the structure
from outside ,
it's generally used on stack defenition
Dec 20 '11 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Tino | last post: by
7 posts views Thread by Raxit | last post: by
reply views Thread by Shrage H. Smilowitz | last post: by
5 posts views Thread by kselvaakumar | last post: by
5 posts views Thread by Bob Altman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.