Questions tagged [globals]

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

335 questions
264
votes
7 answers

Using global variables between files?

I'm bit confused about how the global variables work. I have a large project, with around 50 files, and I need to define global variables for all those files. What I did was define them in my projects main.py file, as following: #…
user1632861
57
votes
13 answers

Where are constant variables stored in C?

I wonder where constant variables are stored. Is it in the same memory area as global variables? Or is it on the stack?
user188276
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,227
  • 9
  • 51
  • 85
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
  • 20,762
  • 4
  • 50
  • 72
24
votes
3 answers

3 questions about extern used in an Objective-C project

When I use the word extern before a method or variable declaration, am I making it global and therefore readable/writable/usable over the entire project ? If I use extern before a keyword, is there any chance it is still not accessible by part of…
aneuryzm
  • 55,858
  • 96
  • 259
  • 471
22
votes
1 answer

Is it safe to modify the output of globals()?

The documentation for the locals() function specifically warns not to modify its output, as interpreters may not reflect changes in the local scope. I'm assuming that means the Python spec doesn't require it, even though it works in CPython. I'd…
rspeed
  • 1,482
  • 14
  • 20
18
votes
3 answers

Declaring a global array

Hi. I recently learned PHP and am trying to declare a global array so I can access inside a function. But I seem to be missing something because I get the error 'Undefined variable:' Here is my code: global $second_array; $second_array =…
Nistor Alexandru
  • 5,109
  • 9
  • 42
  • 66
17
votes
4 answers

What is meant by “leaking” into global scope?

A while ago, I offered-up a JavaScript design pattern (the Module Pattern - see below) that I got from a John Resig example as part of a solution to someone’s question and I received the following comment: “…that pattern is a bit over engineered…
Prisoner ZERO
  • 12,996
  • 18
  • 80
  • 124
14
votes
3 answers

How to create global object in a C# library

Possible Duplicate: Best way to make data (that may change during run-time) accessible to the whole application? I have a C# library. Can a library have global objects/variables? Can an initialization method for those objects be automatically…
Stefanos Kargas
  • 8,783
  • 21
  • 69
  • 90
12
votes
1 answer

Good practice sharing resources between modules?

I am reorganizing my code and therefore creating new namespaces. I'm changing "static" classes (classes with @staticmethod in each method) for modules. This is the way to go, right? The problem is that I have doubts on how to share the resources…
bgusach
  • 13,019
  • 10
  • 44
  • 61
11
votes
1 answer

What is a good way to share an object between classes?

What is a good way to share an instance of an object between several classes in a class hierarchy? I have the following situation: class texture_manager; class world { ... std::vector objects_; skybox skybox_; } I currently…
Dan Nestor
  • 2,270
  • 1
  • 20
  • 40
9
votes
2 answers

PHPUnit and Globals

I am learning and exploring applications of PHPUnit with PHP 5.2.9 and have run into the globals issue. I have set $backupGlobals to FALSE, included the doc '@backupGlobals disabled' and this doesn't seem to affect the behaviour of PHPUnit's backing…
Malovich
  • 891
  • 5
  • 14
9
votes
2 answers

Is it possible to import to the global scope from inside a function (Python)?

I am trying to import a module from inside a function and have it be available to my whole file the same way it would be if I imported outside any functions and before all the other code. The reason it is in a function is because I don't have much…
scott77777
  • 608
  • 2
  • 7
  • 17
9
votes
1 answer

How does Flask keep the request global threadsafe

In flask every function has access to a request global. How do the designers of flask stop that global from being overwritten in the middle of one request when another one starts?
lemiant
  • 3,593
  • 3
  • 27
  • 36
9
votes
1 answer

Unnamed namespace Vs Global declaration

What is the difference in using unnamed namespace and global declaration? Is there any specific context for using these two? Can we access unnamed namespace components in external source files?
Kaushik
  • 982
  • 1
  • 13
  • 31
1
2 3
22 23