473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What is global object?

What is global object?(not global parameter)
Please give me an example.
Jul 27 '08 #1
5 1561
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. int global;
  2. ...
  3. int main() {
  4.    int local;
  5.    ...
  6.    return 0;
  7. }
  8.  
Any object outside of any function has global scope.

kind regards,

Jos
Jul 27 '08 #2
Banfa
9,065 Expert Mod 8TB
Any object outside of any function not declared as static has global scope.

If it's declared static it only has file scope.

Expand|Select|Wrap|Line Numbers
  1. int global;
  2. static int file_only;
  3. ...
  4. int main() {
  5.    int local;
  6.    ...
  7.    return 0;
  8. }
  9.  
Jul 27 '08 #3
JosAH
11,448 Expert 8TB
Any object outside of any function not declared as static has global scope.

If it's declared static it only has file scope.
Its visibility will not span translation units but its lifetime is still equal to the lifetime
of the entire application. You can even pass references or the address of a
static variable over to other translation units.

kind regards,

Jos
Jul 27 '08 #4
Banfa
9,065 Expert Mod 8TB
True Jos, but then it rather depends on where in the life cycle of the development you are talking about, i.e. scope with in the source or scope with-in the running executable.

The point is that if you really must have global data (and there are some situations when it makes sense) then limiting it's source scope by declaring it static and using a strictly adhered to function interface to access it (i.e. using a ADT) will, in most cases, be more robust and more maintainable than not declaring it static.
Jul 27 '08 #5
JosAH
11,448 Expert 8TB
True Jos, but then it rather depends on where in the life cycle of the development you are talking about, i.e. scope with in the source or scope with-in the running executable.

The point is that if you really must have global data (and there are some situations when it makes sense) then limiting it's source scope by declaring it static and using a strictly adhered to function interface to access it (i.e. using a ADT) will, in most cases, be more robust and more maintainable than not declaring it static.
Yup; even the Standard uses fuzzy wordings w.r.t. lifetime and scope of identifiers.
Most of the time the two are synonymous but using one or the other at certain
times meaning the latter or the first can be confusing in a discussion although
both parties basically agree.

kind regards,

Jos
Jul 27 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: WhyteWolf | last post by:
I'm trying to set a object as global for access through out the rest of my script ... {a basic SQL accessing object} however if I try calling the object from with in another object it acts as if it...
3
by: Brett | last post by:
What is the following code doing? I see evt and event but what is the difference? <input type="radio" id="us_countryFlag1" name="us_country" onclick="togglePurDec(event)">Yes <script>...
1
by: Robert North | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I've just started programming JS, and one question keeps nagging me: I can insert a <script> element anywhere in HTML, and when it's executed...
9
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
4
by: GS | last post by:
Hi, I'd rather start from a good design and go from there so would be greatfull for any input. I have a simple ASP.NET application and would like to make solution elegant. I store settings in...
16
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for...
35
by: eyoung | last post by:
I call a function that takes the unit price and quantity ordered to create an amount...it looks something like this. function calculateCost() { quantity=document.RFO.quantity.value;...
0
by: hynek.cihlar | last post by:
A strange behaviour thatI found in ASP.NET 2.0. I am trying to issue a callback request (handled by ICallbackEventHandler and RaiseCallbackEvent) and a regular GET request in the client browser...
10
by: ma | last post by:
Hello, I want to create a global class. To do this I did the followings: 1- Create a class name test. It has a public variable named mystring. public class test { public string mystring =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.