Talk:Global variable
Computing Stub‑class | |||||||||||||
|
Disagree that global variables to be merged into scope of programming because there's other meaning of global variables for different field, such as economic, sustainable development.
I also disagree with the merge. While scope is very relevant to global variables, the term "global" refers specifically to the widest scope, and use of that particular scope level should be restricted. The two topics are, however, connected, and the articles should definately reference each other. scot 16:51, 3 November 2005 (UTC)
The scheme reference is incorrect
(a) Scheme is a procedural language.
- Changed to Haskell Traxer (talk) 17:03, 3 November 2010 (UTC)
(b) Global variables do not affect referential transparency any more than local variables (see lexical closure).
- Yes, they do. When a call f(x) to a function f modifies a global variable, that function call cannot be replaced by the value returned by f, because calls (to f or other functions) might return different values due to the global variable having a different value than when f(x) was actually executed. Traxer (talk) 17:03, 3 November 2010 (UTC)
- And the same applies to local variables captured via lexical closure. Being global is irrelevant to this. —Preceding unsigned comment added by 203.222.167.145 (talk) 08:20, 12 November 2010 (UTC)
C++ Example is incorrect
Just thought I would mention that in the example provided, int global is not truly "global" in scope but merely at file scope, which is the widest scope possible in C++ (and C). Oddity- (talk) 17:45, 8 November 2009 (UTC)
This is incorrect. A variable which is not declared static
has external linkage, it is truly global, accessible by any module in the system. Another module can declare extern int global
to reference the same global. Omitting the extern keyword in this case would result in a linker error (duplicate global).
Wrong. Linkage is not scope.
- foo.c
int foo;
- bar.c
/* Oh, look -- foo is not in scope here */ int bar(void) {
extern int foo; /* Ok, look -- foo is a local variable here */
}
A file scope variable (e.g. static int global
) is visible only within the module in which it is defined.
EricTetz (talk) 03:27, 10 July 2010 (UTC)
static and global in C
What is the semantical difference in C between a global variable (being declared as int a
) and a static global variable (being declared as static int a
, see static variable)?
Thanks, --Abdull (talk) 17:22, 7 January 2010 (UTC)
See above. A static variable defined at file scope accessible only within the module in which it is defined, a non-static variable defined at file scope is visible to the entire program. See above. You are wrong. Linkage is not scope. EricTetz (talk) 03:27, 10 July 2010 (UTC)