Define external variable declaration, Computer Engineering

Summarize the distinction between an external variable definition and an external variable declaration.

When we have ''declared'' a variable, we have meant that we have told the compiler about the variable; i.e. its type and its name, as well as allocated a memory cell for the variable (either locally or globally). This latter action of the compiler, allocation of storage, is more properly called the definition of the variable. The stricter definition of declaration is simply to describe information ''about'' the variable.  For automatic and register variables, there is no difference between definition and declaration. The process of declaring an automatic or a register variable defines the variable name and allocates appropriate memory. However, for external variables, these two operations may occur independently. This is important because memory for a variable must be allocated only once, to ensure that access to the variable always refers to the same cell.

If an external variable is to be used in a file other than the one in which it is defined, a mechanism is needed to ''connect'' such a use with the uniquely defined external variable cell allocated for it. This process of connecting the references of the same external variable in different files, is called resolving the references.

External  variables  may  be  defined  and  declared  with  a  declaration  statement outside any function, with no storage class specifier. Such a declaration allocates memory for the variable. A declaration statement may also be used to simply declare a variable name with the extern storage class specifier at the beginning of the declaration. Such a declaration specifies that the variable is defined elsewhere, i.e. memory for this variable is allocated in another file. Thus, access to an external variable in a file other than the one in which it is defined is possible if it is declared with the keyword extern; no new memory is allocated. Such a  declaration tells  the compiler  that  the  variable  is  defined  elsewhere,  and  the code  is compiled with the external variable left unresolved. The reference to the external variable is resolved during the linking process

 

Posted Date: 6/14/2013 6:52:04 AM | Location : United States







Related Discussions:- Define external variable declaration, Assignment Help, Ask Question on Define external variable declaration, Get Answer, Expert's Help, Define external variable declaration Discussions

Write discussion on Define external variable declaration
Your posts are moderated
Related Questions
A vertical flashing line that permits the user where text will be inserted.

A component can handle its own events by executing the needed event-listener interface and adding itself as its own event listener.

Efficiency of Vector Processing over Scalar Processing: We know that, a sequential computer processes scalar operands one at a time. Thus, if we have to process a vector of len

Q. Signed 1s complement representation? Another possibility that is also simple is use of signed 1's complement. Signed 1's complement has a principal. Add both numbers includi

Determine the Object oriented principles Many latest applications are being developed based on object oriented principles such as methods, classes, and inheritance. To fulfil

In which page replacement policies Balady’s anomaly occurs? FIFO that is First in First Out.

Explain about the Microsoft and the Netscape With the increasing competition between certain vendors especially the Microsoft and the Netscape, there have been a number of chan

Discuss the concept of segmentation? Segmentation is method for the non contiguous storage allocation. This is different from paging as this supports user's view of his program

How to select valid lines for secondary list? To stop the user from selecting invalid lines, ABAP/4 offers various possibilities.  At the end of the processing block END-OF-SEL

Write a program to read in a positive integer and check whether it is prime or not? /* Program to check whether a given number is prime or not*/] # include # include