Questions tagged [global]

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

4669 questions
18
votes
1 answer

In CodeIgniter, where should I declare my global variables?

I want to declare some global variables and global constants. Normally, I would put them in the includes/global.php of my own custom framework. Where should I define globals in CodeIgniter? Here's an example of the globals I want to…
John
  • 32,403
  • 80
  • 251
  • 422
18
votes
6 answers

Okay to declare static global variable in .h file?

static keyword keeps the scope of a global variable limited to that translation unit. If I use static int x in a .h file and include that .h file every other file, won't they all belong to the same translation unit? Then, won't x be visible…
batman
  • 5,022
  • 11
  • 52
  • 82
17
votes
10 answers

"Pythonic" way to "reset" an object's variables?

("variables" here refers to "names", I think, not completely sure about the definition pythonistas use) I have an object and some methods. These methods all need and all change the object's variables. How can I, in the most pythonic and in the best,…
user103798
17
votes
1 answer

Why is globals() a function in Python?

Python offers the function globals() to access a dictionary of all global variables. Why is that a function and not a variable? The following works: g = globals() g["foo"] = "bar" print foo # Works and outputs "bar" What is the rationale behind…
Rolf Kreibaum
  • 273
  • 1
  • 7
17
votes
4 answers

How can I define global variables inside a twig template file?

Is it possible to set global variables in a twig file, so that I can access that variables from other files, macros and blocks. For example, I want to have variables.twig file and in it set my variables and then I can include it in other…
Amir Ajoudanian
  • 313
  • 1
  • 3
  • 8
17
votes
4 answers

How to declare global variable inside function?

I have problem creating global variable inside function, this is simple example: int main{ int global_variable; //how to make that } This is exactly what I want to do: int global_variable; int main{ // but I wish to…
user3137147
  • 243
  • 1
  • 4
  • 8
17
votes
2 answers

Perl - Global variables available in all included scripts and modules?

So lets say I have a main.pl script and in that script I need to declare some variables (any kind of variable constant or normal) and those variables need to be available through all scripts and modules that I'll include from that main.pl script…
SLC
  • 2,167
  • 2
  • 28
  • 46
17
votes
1 answer

Python: Difference between 'global' & globals().update(var)

What is the difference between initializing a variable as global var or calling globals().update(var). Thanks
frank
  • 195
  • 2
  • 2
  • 8
17
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
  • 10,547
  • 22
  • 76
  • 101
16
votes
3 answers

Preferred way to attach AudioEffect to global mix?

In Android, AudioEffect API, all of the builtin effects such as Equalizer come with a warning "NOTE: attaching an Equalizer to the global audio output mix by use of session 0 is deprecated. " If this is deprecated, then what is the replacement API?…
yano
  • 4,095
  • 3
  • 35
  • 68
16
votes
6 answers

php global variable modifier not working

I'm using the basic php example for the global modifier, and it doesn't work for me :-| $a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo "***: ".$b; Here is the result... $ ***: 2 Is there any parameter on the…
kanji
16
votes
5 answers

Define global namespace/variable within a TypeScript module

In TypeScript I can define a global/top-level namespace and use it in another file like so: namespace foo.blah { export function baz() { console.log('hello'); } } And in another file, this works: foo.blah.baz(); However, if I then…
Jesse
  • 6,725
  • 5
  • 40
  • 45
16
votes
2 answers

Should I worry about "window is not defined" JSLint strict mode error?

This won't pass JSLint in strict mode: "use strict"; (function (w) { w.alert(w); }(window)); The error--from jslint.com--looks like this: Problem at line 4 character 3: 'window' is not defined. }(window)); Implied global: window 4 Do I need to…
Kent Brewster
  • 2,480
  • 2
  • 22
  • 27
16
votes
3 answers

Java function (method) available everywhere (global)

I've recently (4 days ago) started programming in JAVA. I have some overall programming experience from C++ and PHP. My question is: can we implement a function in JAVA, that is available in all classes? I'm thinking of some global logging function,…
Mars
  • 867
  • 2
  • 13
  • 22
16
votes
3 answers

Can you extern a #define variable in another file?

For example abc.c contains a variable #define NAME "supreeth" Can extern the variable NAME in def.c?
user1295872
  • 461
  • 1
  • 6
  • 16