ALERT

Cisco CloudCenter: Get the Hybrid IT Advantage

Global Variable

Definition - What does Global Variable mean?

A global variable is a programming language construct, a variable type that is declared outside any function and is accessible to all functions throughout the program. A group of global variables is called a global state or global environment because when combined, they define various aspects of a program or the environment when the program runs. A global variable is usually declared on top of all functions and is kept to a minimum, as all functions can manipulate them during the program’s run time, which is considered dangerous by most programmers because they may accidentally be changed, resulting in bugs.

Techopedia explains Global Variable

Global variables, as the name implies, are variables that are accessible globally, or everywhere throughout the program. Once declared, they remain in memory throughout the runtime of the program. This means that they can be changed by any function at any point and may affect the program as a whole. During the early years of computers where memory was very limited, they became considered bad practice because they took up valuable memory space and it was very easy for the programmer to lose track of their values, especially in long programs, leading to bugs that can be very hard to locate. Source code is best understood when the scope of its individual elements are limited, so because of their non-locality, it is hard to keep track of where they have been changed or why they were changed.

Even with this stigma, global variables are valuable in functions that do not share a ‘’caller and callee” relation, such as signal handlers and concurrent threads. With the exception of global variables declared as read only values in protected memory, codes should deploy proper encapsulation in order to be considered “thread-safe.”

Early versions of non-structured languages like BASIC, COBOL and Fortran only used global variables. However languages like Lua, Forth and Perl use global variables by default as do most shell scripts.

Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.