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

static

P: n/a
vim
hello guys

plz tel me the differances between global static and local static.
If possible with examples

Mar 22 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
vim wrote:
hello guys

plz tel me the differances between global static and local static.
If possible with examples
Please explain what you mean by "global static" and "local
static," because the Standard that defines the C language does
not use either phrase.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 22 '07 #2

P: n/a
vim
On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalidwrote:
vim wrote:
hello guys
plz tel me the differances between global static and local static.
If possible with examples

Please explain what you mean by "global static" and "local
static," because the Standard that defines the C language does
not use either phrase.

--
Eric Sosman
esos...@acm-dot-org.invalid



Global static variable is a variable declared(with "static" keyword)
outside function.Local is declared inside any function with "static"
keyword.

Mar 22 '07 #3

P: n/a
"Eric Sosman" writes:
vim wrote:
>hello guys

plz tel me the differances between global static and local static.
If possible with examples

Please explain what you mean by "global static" and "local
static," because the Standard that defines the C language does
not use either phrase.
I normally leave such question to the language mavens.

A variable declared as static within a function preserves information
between successive calls to that function. For example, a random number
generator(1) can preserve the seed to be used to generate the next number.

A variable or function declared as static external to any function "hides"
the item from code in other source files(2), thus preventing inadvertent -
or perhaps malicious, usage. By default functions are "known" everywhere
and variables *can* be known by use of an extern qualifier(3) by the
*receiver*, not the giver.

Function declarations *can* be made within a function, but it is a rarely
used style. My guess is that the addition of static would have no effect.
.................
(1) Yes I know the generator does not generate random numbers. Get a life
fer crissakes!!
(2) Yes I know the dammed thing is called a translation unit!
(3) The proper name may not actually be "qualifier". Despite that, a
person speaking ordinary English would understand.
Mar 22 '07 #4

P: n/a
vim wrote:
On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalidwrote:
>vim wrote:
>>hello guys
plz tel me the differances between global static and local static.
If possible with examples
Please explain what you mean by "global static" and "local
static," because the Standard that defines the C language does
not use either phrase.

--
Eric Sosman
esos...@acm-dot-org.invalid


Global static variable is a variable declared(with "static" keyword)
outside function.Local is declared inside any function with "static"
keyword.
Mar 22 '07 #5

P: n/a
vim wrote:
On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalidwrote:
>vim wrote:
>>hello guys
plz tel me the differances between global static and local static.
If possible with examples
Please explain what you mean by "global static" and "local
static," because the Standard that defines the C language does
not use either phrase.

Global static variable is a variable declared(with "static" keyword)
outside function.Local is declared inside any function with "static"
keyword.
Both variables have the same storage duration, but they
differ in scope and in linkage. The scope of the file-scope
variable ("global static") extends from its declaration to
the end of the translation unit, while that of the block-scope
variable ("local static") extends from its declaration to the
end of the block containing it (both scopes can be "interrupted"
by inner declarations). The file-scope variable has internal
linkage, while the block-scope variable has no linkage.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 22 '07 #6

P: n/a
"osmium" <r1********@comcast.netwrites:
Function declarations *can* be made within a function, but it is a rarely
used style. My guess is that the addition of static would have no effect.
It would be a constraint violation. See C99 6.7.1:

The declaration of an identifier for a function that has
block scope shall have no explicit storage-class specifier
other than extern.
--
"I've been on the wagon now for more than a decade. Not a single goto
in all that time. I just don't need them any more. I don't even use
break or continue now, except on social occasions of course. And I
don't get carried away." --Richard Heathfield
Mar 22 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.