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
2 answers

How to access the input tag value

Update: I solved it by creating a new variable and used it and assigned that variable to finalPrice Improving the question as I think it can be done different way I wanna access the value finalPrice defined here just above the…
user022yufjb
  • 157
  • 1
  • 3
  • 11
2
votes
2 answers

Should I use extern?

I have the following files: pass_args.c pass_args.h kbd.c kbd.h main.c There are 3 global variables that I would need to use: freq, amp and waveforms. Should I declare those variables in every .h files by using extern and define the variable in…
Jayden
  • 25
  • 7
2
votes
2 answers

JavaScript Closures use global setting object or pass it to each function

another question concerning javascricpt closures. I have a global "settings object". Is it better to use it from within functions in global scope or pass the object every time a function needs to access the object? For a better understanding a…
mayrs
  • 2,299
  • 2
  • 24
  • 35
2
votes
0 answers

Declaring global instance variables available for Console/Kernel::schedule() in Laravel

I have created a UniqueMessage class which I want to use in log statements inside /Console/Kernel::schedule() to suppress repeated log messages. I have tried to make an instance of my UniqueMessage class in the constructor for Kernel but it seems to…
Arne
  • 31
  • 2
2
votes
1 answer

Reading global flag does not work for CPU>GPU data exchange in CUDA

I try to do a simple uni-directional communication between a CPU and a K80 GPU using CUDA. I want to have a bool cancel flag that resides in global memory and is polled by all running GPU/kernel threads. The flag should default to false and can be…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
2
votes
1 answer

Global state storage in Typescript

My code : import { createContext, ReactNode, useReducer } from "react"; interface children { children: ReactNode } export const Store = createContext(null); const initialState = { cart: {cartItems:[]} } function reducer(state: any,…
2
votes
1 answer

python function global and local scope confusion

I have a code in which I declare a variable globally. Then inside a function, when I try to use it, it gives an error Unbound variable is not declared My code: count_url =1 def foo(): ... ttk.Label(canvas1,…
xlmaster
  • 659
  • 7
  • 23
2
votes
1 answer

My tableview crash when i scroll

I don't undestand... i succeed in populate my table view but when i scroll it crash without message.. i create my tabQuestion with a NSMutablearray and then add this in my delegate : cellForRowAtIndexPath NSDictionary *question =…
Sylvain Bessot
  • 181
  • 1
  • 3
  • 13
2
votes
1 answer

How to get the total number of Wordpress Posts from an Author ID?

I've been scouring everywhere and can't seem to find this. I know the WP variable within the loop can use $post_count but I'm writing from an external function. I've set global wp_query so I should be able to pull out the number, and I have the user…
Jake
  • 1,285
  • 11
  • 40
  • 119
2
votes
0 answers

is a instance of the python class default to be global?

according to my understanding, in python, if i want to change/write the value of a global variable in a function, i should firstly and locally make a global declaration of this global variable in the function, whereas if only access/read the value…
furynerd
  • 109
  • 1
  • 8
2
votes
0 answers

Understanding global variable declaration and definition differences between C and C++

This is a minimal example to reproduce a linker error from a program that worked in C but failed when compiling with C++ (gcc/g++ 8.1.0). I already know how to solve it using extern, what i want to find out is why it results in a linker error only…
Africa
  • 21
  • 1
2
votes
0 answers

Access window object set in one angular app in another

I have a parent and child application built in angular. In the child application I’m exposing a method on the window object. The child application main.js is loaded inside the parent application (script). However, inside the parent, the window…
2
votes
1 answer

Accessing global variables in pthreads in different c-files

I have a main.c with a global variable called int countboards. In the main() I start a pthread, that listens to ONE TCP-Connection and runs that through (progserver.c). Means, this thread will never return. In the main() I enter the function…
Berschi
  • 2,605
  • 8
  • 36
  • 51
2
votes
1 answer

How can I access global variable in vue 3 outside vue component?

I defined my global variable in main.js file like this const app = Vue.createApp({}) app.config.globalProperties.$myGlobalVariable = globalVariable*** and then when I tried to access this variable $myGlobalVariable in other js file it is…
2
votes
4 answers

Is it possible to create a variable, that doesn't change on refresh the page, in javascript?

After I ask this question: I was thinking about this solution: Create a boolean flag inside the javascript script and make it true: true indicates refreshing the page using the browser. false indicates refreshing the page using a button. Inside…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417