473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

static

vim
hello guys

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

Mar 22 '07 #1
6 4739
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
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
"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
9
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
1
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.