Jump to content

Talk:Global variable

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 203.222.167.145 (talk) at 08:30, 12 November 2010 (The scheme reference is incorrect). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

WikiProject iconComputing Stub‑class
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StubThis article has been rated as Stub-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Note icon
This article has been automatically rated by a bot or other tool as Stub-class because it uses a stub template. Please ensure the assessment is correct before removing the |auto= parameter.

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)[reply]

The scheme reference is incorrect

(a) Scheme is a procedural language.

Changed to Haskell Traxer (talk) 17:03, 3 November 2010 (UTC)[reply]

(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)[reply]
And the same applies to local variables captured via lexical closure. Being global is irrelevant to this.

 (let ((a 10))
   (lambda ()
     (set! a (+ a 1))
     a))

The problem is due to free variables in the presence of mutation. Global scope is completely irrelevant.

—Preceding unsigned comment added by 203.222.167.145 (talk) 08:20, 12 November 2010 (UTC)[reply]

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)[reply]

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.

  1. foo.c

int foo;

  1. 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)[reply]


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)[reply]

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)[reply]