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

Property 'users' does not exist on type 'Global & typeof globalThis' although modifying global with global.d.ts

I am trying to develop a project in the one I need to include global variables that could be accessed from anywhere. Normally, with javascript I would be able to write something like this: global.users = {} but this is not that easy in typescript,…
2
votes
3 answers

Define a global variable template?

Usually, we do declare but not define a global variable in the header file. However, we define templates in it. Then the issue arises: is it possible to define a global variable template? template uint8_t BitMask =…
2
votes
0 answers

Initialising global variables in C in Harvard CPU

I build a 32-bit RISC-V CPU with Harvard architecture and I want to write programs for it in C. I have a RISC-V compiler set (https://xpack.github.io/riscv-none-embed-gcc/) that can do just that and works fine - for most things. The problem starts…
2
votes
1 answer

Global variables between modules

I have not been able to find a reason why the matter does not work for me, so I would like to ask a question here. I have 2 files: file2.py: def test(): global justTry justTry = "hello" and main.py: from file2 import * def main(): …
xHybrid
  • 23
  • 1
  • 4
2
votes
5 answers

Is Test_xxx func safe to access shared data in golang?

I'm confused about the golang unit test. I have 2 Test_xxx funcs , like Test_1 and Test_2. In Test_1, i will change a global variable , can Test_2 see the change? Furthermore, if i use monkey patch instead of changing global var, will the other…
wymli
  • 1,013
  • 1
  • 7
  • 11
2
votes
1 answer

Parameters File to Store All Variables

Background: So I've created an application that is basically a large preference dialog where the user can configure a number of pages, each with a bunch of different settings. These settings are in the form of dropdowns and text boxes. I want to…
Jon
  • 3,154
  • 13
  • 53
  • 96
2
votes
2 answers

FastAPI: global variable vs module variable

I would like to have a global variable limited to a FastAPI request execution but common to multiple modules. Below is a small example to explain the problem: I built a very simple app with a main file app.py and a module mymodule. For each test i…
Guillaume B
  • 23
  • 1
  • 4
2
votes
0 answers

globalVariables and Function Behavior

Running R CMD check on a package of mine throws a note regarding undefined global functions or variables. Consider the following example: mypackage: no visible binding for global variable 'a' mypackage: no visible global function definition for…
Chr
  • 1,017
  • 1
  • 8
  • 29
2
votes
2 answers

R list all variables created in global environment after a certain point

In R, is there a function or other way to make a list of all variables that have been created in the global environment after a certain point in the script? I am using an R notebook so it has chunks of code, and the goal is to eventually delete all…
Rachel
  • 109
  • 8
2
votes
1 answer

C99: compiler optimizations when accessing global variables and aliased memory pointers

I'm writing C code for an embedded system. In this system, there are memory mapped registers at some fixed address in the memory map, and of course some RAM where my data segment / heap is. I'm finding problems generating optimal code when my code…
Giovanni Bajo
  • 1,337
  • 9
  • 15
2
votes
3 answers

Python 3 Pycharm ide warning

I actually don't have any question about my code but i use a ide named pycharm while running my code i don't get any error but my ide gives me a warning why is that so? Here's my code : def hi(): global d d = 5 hi() print(d) My code works…
Arkodeep Ray
  • 174
  • 14
2
votes
0 answers

How to share variables between JS scripts in a chrome extension

Suppose the following situation : In a chrome extension, I have 1 popup.html, in which a scirpt runs, popup.js like so :

Hello World

2
votes
0 answers

How do i declare a global variable in php in order to recive custom emails?

i'm workin on my portfolio and, at the end of it, there is a form (name, email, message). This form needs to send an email to my personal gmail account but i'm having hard times trying to set global variables. Form is working, this is the html code …
Elle
  • 43
  • 6
2
votes
1 answer

JavaScript IIFE functions and variable scope

Reading JavaScript Puzzlers!, I was following up until I came across this kind of situation. The code var name = "abc"; (function () { console.log(name); var name = "xyz"; console.log(name); }) (); returns undefined xyz But this…
Livio
  • 300
  • 1
  • 10
2
votes
1 answer

Best way to initialize html elements in JavaScript for reusability?

The way I did this was by getting the html elements and declaring them as global const variables inside a function() {} that encapsulates the whole program. It works, but I'm unsure if this is good practice. Is there a way to allow reusability of an…
1 2 3
99
100