By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

static structure

P: 3
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
Share this Question
Share on Google+
7 Replies


Savage
Expert 100+
P: 1,764
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

Expert 100+
P: 181
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

P: 3
i have to know about static struct in c-language..
Jun 1 '07 #4

P: 3
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
Expert Mod 5K+
P: 8,916
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
Expert 100+
P: 1,251
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

P: 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.