Questions tagged [global-variables]

Global variables are variables that are accessible from all elements of a software component.

Global variables are variables that are accessible from all elements of a software component.

Global variables are used to share information between elements of a component and to store a part of the component's state. They therfore:

  • create a hidden coupling between all the elements that use them;
  • are a source of accidental bugs and inconsistencies, when changes and side-effects are not sufficiently controlled.
8810 questions
2
votes
0 answers

Python: A global variable in a local function possible?

Consider the programm: x = 0 def f(): c = 2 def g(): c = 4 print(c) print(c) I want that the c in g() is the same as the c in f(). Normally one would use the keyword global within g(), but this is not possible,…
2
votes
3 answers

What happens to a variable without the "var" keyword inside a function?

function bla() { a=5; } Does a automatically become a global variable? And when exactly is it set? when the functions are being read for the first time and put into memory or only at the execution of the function?
ilyo
  • 35,851
  • 46
  • 106
  • 159
2
votes
2 answers

How global variable works in parallel programming with Python?

I have this code. In the sequential approach the message "no ok" is printed, while in the parallel approach the message ["ok", "ok", "ok"] is printed instead of the ["not ok", "not ok", "not ok"] that I expected. How could I change variable globVar…
2
votes
2 answers

How does Ruby compared to Javascript in globals?

I'm getting hung up on why Javascript globals are so dangerous, when a similar (?) behavior is in Ruby. When you make a variable, like foo, and it's bound to main, isn't that the same thing as having a Javascript variable bound to window?
Casey Chow
  • 1,794
  • 4
  • 17
  • 29
2
votes
1 answer

Is it valid to use extern in a local scope to unshadow a global variable?

Is this extern declaration in a nested local scope a valid and defined way to bring the global a back into the scope? int a = 1; // may be in another file void main() { int a = 2; // hides the global { cout << a << endl; // prints 2 …
Gonen I
  • 5,576
  • 1
  • 29
  • 60
2
votes
1 answer

javascript global variable returning to previous state on next event call

So i have the global variable var INSIDE_GLOBAL = {} ; INSIDE_GLOBAL.current_search = get_new_current_search(); function get_new_current_search() { return { stack:[], search_options: { keywords: "" }, …
David Rice
  • 1,111
  • 1
  • 11
  • 24
2
votes
1 answer

How are variable assignments detected in a function?

When trying to execute the following code: a = 1 def test_variable(): if False: a = 2 print(a) test_variable() It fails with UnboundLocalError: local variable 'a' referenced before assignment. This is in line with how local and…
filaton
  • 2,257
  • 17
  • 27
2
votes
1 answer

How I can change value varible in a file in another file in javascript

I want to change value variable in an index.js in another file, but i can't do that and this is my code example index.js var length = 0; client.commands.get('join').excute(length); anotherfile.js module.exports = { name: 'join', …
2
votes
5 answers

How can I make global variables un-accessible by specific functions In C

I just need a way to restrict access of a global variable per my functions in C not C++ static int global_int = 10; int main(void) { global_int = 20; // allowed } void f() { global_int = 30; // global_int cannot be used here } What…
mada
  • 1,646
  • 1
  • 15
2
votes
0 answers

Profiling global variables

Is it possible to find out the memory usage of global variables in Go? For example have a look at this code: package main import ( "fmt" "math/rand" _ "net/http/pprof" "os" "runtime" "runtime/pprof" "time" ) var…
Hirbod Behnam
  • 577
  • 2
  • 7
  • 26
2
votes
2 answers

How to override module name (__name__)?

I have two classes in separate files, a.py and b.py. # a.py import logging LOG = logging.getLogger(__name__) class A: def name(self): # Do something LOG.debug("Did something") # LOG reads __name__ and print it. I can not…
osflw
  • 79
  • 1
  • 8
2
votes
1 answer

Oracle APEX 21 Application Item value that is displayed is old

Page 1 of my app is an interactive grid that displays a "Create Holds" button. Records can be selected and saved on Page 1. Then, when the "Create Holds" button is clicked, page 11 (a modal window) is displayed, prompting for the hold…
LG-C
  • 47
  • 6
2
votes
1 answer

Why is my variable inside a function not defined even if it's global?

So I made a function to open sites: import webbrowser def go_to_url(link): global YT, Reddit, SO YT = 'youtube.com' Reddit = 'reddit.com' SO = 'stackoverflow.com' webbrowser.open(link) go_to_url(YT) No syntax error when…
Andrew
  • 54
  • 1
  • 4
2
votes
3 answers

Problem with global variables in multiprocessing in Python

I'm new to Python programming (using v.3.8.8) and have a very basic question on accessing global variables in a multithreading program using processes. For example, I have the following simple code: from multiprocessing import Process global_var =…
Miguel
  • 91
  • 1
  • 3
2
votes
1 answer

Why global arrays does not consume memory in readonly mode?

The following code declare a global array (256 MiB) and calculate sum of it's items. This program consumes 188 KiB when runing: #include #include using namespace std; const unsigned int buffer_len = 256 * 1024 * 1024; // 256…
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
1 2 3
99
100