473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

static

vim
hello guys

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

Mar 22 '07 #1
6 4741
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
4557
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
6551
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
1894
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
2088
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
2643
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
2541
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
6149
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
3505
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
5829
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
5974
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
7108
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
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6847
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
7352
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
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.