Questions tagged [global]

Refers to a space where variables and other items may be accessed from any scope.

4669 questions
31
votes
5 answers

C++: When (and how) are C++ Global Static Constructors Called?

I'm working on some C++ code and I've run into a question which has been nagging me for a while... Assuming I'm compiling with GCC on a Linux host for an ELF target, where are global static constructors and destructors called? I've heard there's a…
Matthew Iselin
  • 10,400
  • 4
  • 51
  • 62
30
votes
5 answers

Python - Easiest way to define multiple global variables

I am trying to look for an easy way to define multiple global variables from inside a function or class. The obvious option is to do the following: global a,b,c,d,e,f,g...... a=1 b=2 c=3 d=4 ..... This is a simplified example but essentially I need…
Stephen Gelardi
  • 485
  • 1
  • 5
  • 9
30
votes
8 answers

Python: "global name 'time' is not defined"

I'm writing a silly program in python for a friend that prints "We are the knights who say 'Ni'!". then sleeps for 3 seconds, and then prints "Ni!" twenty times at random intervals using the random module's uniform() method. Here's my code: from…
Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
30
votes
7 answers

Objective C defining UIColor constants

I have a iPhone application with a few custom-defined colors for my theme. Since these colors will be fixed for my UI, I would like to define the colors in a class to be included (Constants.h and Constants.m). How do I do that? (Simply defining them…
futureelite7
  • 11,462
  • 10
  • 53
  • 87
29
votes
3 answers

WPF - Global Style?

Is there a way to setup global styles for my WPF application? What I'm hoping to do is apply a style to all my Buttons that also have an Image child.
Sonny Boy
  • 7,848
  • 18
  • 76
  • 104
29
votes
7 answers

Global functions in javascript

I'm new to js and trying to understand global and private functions. I understand global and local variables. But if I have an html named test.html and a 2 js files named test1.js and test2.js. Now I include the test1.js and test2.js in test.html…
ugandajs
  • 291
  • 1
  • 3
  • 3
29
votes
5 answers

C# Namespace Alias qualifier (::) vs Dereferencing Operator (.)

Quick and simple question. I kind of understand what the Namespace Alias qualifier does, it's for accessing members in a namespace, however so does the dereferencing operator. I am really baffled as to the difference in this situation, why you would…
Francisco Aguilera
  • 3,099
  • 6
  • 31
  • 57
29
votes
4 answers

Global variable "count" ambiguous

#include using namespace std; int count = 0, cache[50]; int f(int n) { if(n == 2) count++; if(n == 0 || n==1) return n; else if (cache[n] !=- 1) return cache[n]; else cache[n]= f(n-1) + f(n-2); return cache[n];…
user801154
28
votes
3 answers

How to share/export a global variable between two different perl scripts?

How do we share or export a global variable between two different perl scripts. Here is the situation: first.pl #!/usr/bin/perl use strict; our (@a, @b); ......... second.pl #!/usr/bin/perl use strict; require first.pl; I want to use global…
Cthar
  • 633
  • 2
  • 8
  • 11
28
votes
7 answers

What is the difference between a static global and a static volatile variable?

I have used a static global variable and a static volatile variable in file scope, both are updated by an ISR and a main loop and main loop checks the value of the variable. here during optimization neither the global variable nor the volatile…
Manoj Doubts
  • 13,579
  • 15
  • 42
  • 45
28
votes
2 answers

Best Practice for globals in clojure, (refs vs alter-var-root)?

I've found myself using the following idiom lately in clojure code. (def *some-global-var* (ref {})) (defn get-global-var [] @*global-var*) (defn update-global-var [val] (dosync (ref-set *global-var* val))) Most of the time this isn't even…
Jeremy Wall
  • 23,907
  • 5
  • 55
  • 73
28
votes
8 answers

Strange behavior of static global variable

I know that this program is not using the static variable in an appropriate way, but it shows how to reproduce a behavior I have seen : Main.cpp : int main(){ MyObject* p = new MyObject(); Header::i = 5; printf("i %i\n", Header::i); …
Arcyno
  • 4,153
  • 3
  • 34
  • 52
28
votes
7 answers

global variables in php not working as expected

I'm having trouble with global variables in php. I have a $screen var set in one file, which requires another file that calls an initSession() defined in yet another file. The initSession() declares global $screen and then processes $screen further…
Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
27
votes
6 answers

How do you define a global function in C++?

I would like a function that is not a member of a class and is accessible from any class. I assume I would have to #include the header file where the function is declared, but I don't know where to define such a global function. Are there good…
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
27
votes
6 answers

PHP $this variable

I am reading some PHP code that I could not understand: class foo { function select($p1, $dbh=null) { if ( is_null($dbh) ) $dbh = $this->dbh ; return; } function get() { return $this->dbh; } } I can't find $this->dbh…
wordpressquestion
  • 745
  • 1
  • 7
  • 18