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
1 answer

C++ static global objects workarounds?

I have a C++ program that crashed due to a bug. It would not even get to main as a NULL pointer was accessed in one of its static global object's contructor functions. To make matters worse the pointer was NULL but should have been set by another…
ojblass
  • 21,146
  • 22
  • 83
  • 132
2
votes
1 answer

Python 2.7.2 global variables + tkinter

I'm having some problems with the global variables: #Dev by Mkee import Tkinter as tk import sys, random globvar = 0 class Shuffle(object): def __init__(self,master=None): self.master=master self.text=tk.Label(master, text="Type…
Thurax
  • 77
  • 2
  • 6
2
votes
2 answers

Global Values return to Original Values After AJAX (jQuery)

I am relatively new to jQuery, I am trying to work around this code but constantly failing, the problem I'm facing is, I have a gloval array (Roles_Permission), I am able to use this in my AJAX request, I am also able to make changes to the Array's…
rac3b3nn0n
  • 861
  • 2
  • 12
  • 26
2
votes
3 answers

Accessing data from a callback

I have some code and data, both currently encapsulated within a struct, which in turn is within a namespace. I'm trying to integrate an external library, which makes use of old-fashioned callbacks. I need access to my data within the context of the…
Nairou
  • 3,585
  • 5
  • 29
  • 47
2
votes
4 answers

What must an external JavaScript file look like to avoid global variables and methods?

I have the following piece of code on my page: And in myJavaScript.js I have the following: (function…
Brendan Vogt
  • 25,678
  • 37
  • 146
  • 234
2
votes
2 answers

Global Variable Curiosity

Say i have a bunch of functions that will be using int = price; for instance. Can i set this outside int main and all the functions so they all call to it? For example here i called int price outside main but there will be more functions using it.…
soniccool
  • 5,790
  • 22
  • 60
  • 98
2
votes
1 answer

How to set global variable with Power Apps OnStart property

I have created blank canvas app and I want to create product details like product name, price, category,quantity, color, etc..., by using set function with OnStart property. Please, suggest any information about this. I want to create global…
2
votes
6 answers

How to stop a variable from being destroyed on pressing F5 in javascript

I have the following code
user1432124
2
votes
1 answer

Global variable in crystal reports

I'm trying to keep a running total of teachers, support staff and managers in crystal reports, I've decided to do this using global variables, I know it'd be possible in other ways but I want to give global variables a go. …
pluke
  • 3,832
  • 5
  • 45
  • 68
2
votes
1 answer

Modifying functions and their names based on variables in global environment

Let's say I have a feature dataframe, f f = data.frame(X1 = 1:10, X2 = 11:20, X3 = 21:30) And an outcome vector, o o = 1:10 Is there a way for me to create the following 3 functions based on f's variables -- i.e.,…
Maria
  • 31
  • 4
2
votes
1 answer

C++ - namespaces with global variables and functions using extern

Namespaces containing global variables and functions I am looking for some pointers to what can be considered "good practice" when working with modifiable global variables and functions inside a namespace and how these are accessed by different…
Fredrik HD
  • 105
  • 6
2
votes
1 answer

Submission and custom input on GeeksForGeeks gives different judge result on same test case

I was practicing with a GeeksForGeeks problem Fractional Knapsack: Given weights and values of N items, we need to put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note: Unlike 0/1 knapsack, you are…
2
votes
1 answer

Rust: How to solve "one type is more general than the other" error when using thread local OnceCell?

I'm on 1.70 version of rust playing with recently added OnceCell in std. I'm trying to create global configuration object in thread local storage wrapped in OnceCell. I do that purposefully to avoid unnecessary synchronization overhead of…
2
votes
1 answer

How to initialise a global object or variable and reuse it in every FastAPI endpoint?

I am having a class to send notifications. When being initialised, it involves making a connection to a notification server, which is time-consuming. I use a background task in FastAPI to send notifications, as I don't want to delay the response due…
LOrD_ARaGOrN
  • 3,884
  • 3
  • 27
  • 49
2
votes
3 answers

Extern global variable usage in Standard Library

Global Variables are usually discouraged. What is the rational behind Global Variables with external linkage in C++ Standard Library? Is it true that extern variable is only declaration but not definition? An example is the gcc implementation of…
cpp
  • 265
  • 1
  • 6