Static Globals vs Globals

Hi,
I am extremely sorry for posting this question here
but since i am not subscribed to any other site i
would like to know the difference between
static globals and normal global variables. Are both
of them the same thing???

Thanx in advance


Do You Yahoo!?
Thousands of Stores. Millions of Products. All in one Place.
http://shopping.yahoo.com/

Hi,

I am extremely sorry for posting this question here
but since i am not subscribed to any other site i

That’s OK.

would like to know the difference between
static globals and normal global variables. Are both
of them the same thing???

A static global variable is only accessible by functions in the same module
in which it is declared, it is static to the module.

A normal global variable can be accessed from the module it’s declared in,
and any other module using the ‘extern’ keyword.

HTH

Alun Carp
Driver Development Team Leader
Data Encryption Systems Limited

MSDN Library says this:

When modifying a variable or function at file scope, the static keyword
specifies that the variable or function has internal linkage (its name
is not visible from outside the file in which it is declared).

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Ramakrishnan
Jayaraman
Sent: Thursday, November 09, 2000 4:10 PM
To: NT Developers Interest List
Subject: [ntdev] Static Globals vs Globals

Hi,
I am extremely sorry for posting this question here
but since i am not subscribed to any other site i
would like to know the difference between
static globals and normal global variables. Are both
of them the same thing???

Thanx in advance


Do You Yahoo!?
Thousands of Stores. Millions of Products. All in one Place.
http://shopping.yahoo.com/


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)

> I am extremely sorry for posting this question here

but since i am not subscribed to any other site i
would like to know the difference between
static globals and normal global variables. Are both

“static” global has a file scope and is not visible to any other source
files.
Usual globals are visible to the other source files and have the binary
file
scope, not the source file.
You will have linker errors if you will have 2 non-static globals with the
same name in 2 files.
The same is true on functions.

Anyway I would suggest you to read a good book on C.

Max

>-----Original Message-----
>From: xxxxx@lists.osr.com [mailto:bounce-ntdev->xxxxx@lists.osr.com]On Behalf Of Ramakrishnan Jayaraman
>Sent: Thursday, November 09, 2000 4:10 PM
>To: NT Developers Interest List
>Subject: [ntdev] Static Globals vs Globals

Hi,
>I am extremely sorry for posting this question here
>but since i am not subscribed to any other site i
>would like to know the difference between
>static globals and normal global variables. Are both
>of them the same thing???

Thanx in advance

Hi for understanding look this
3: static int st_k;
4: int s_k;
5: main()
6: {
00401010 mov dword ptr [__cfltcvt_tab(0x00413c80)+0AC0h],9
7: st_k=9;
8: s_k=10;
0040101A mov dword ptr [_s_k(0x00413f88)],0Ah
9: }
00401024 ret
As you can see, s_k would be accessed through ‘__cfltcvt_tab’ table (that makes compiler’s work simple when you try to access variable from other module using ‘extern’ keyword or when you makes changes and rebuild project, but it’s take execution time longer because of plusing offset ), access to ‘static’ variable goes directly to it memory address.