N
Neelesh Bodas
Hello All,
I was just listing down various ways in which variables can be created
and destroyed in C++. (On the lines of 10.4.3 TC++PL Ed 3)
Putting the summary here for corrections, comments, criticism, advices,
improvements.
Abbreviation:
Created (C)
Destroyed (D)
Lifetime (L)
Visibility (V)
Location (Lo)
Linkage (Li)
----------------------------
1.Local data inside a function
C When control hits the definition
D At the end of scope
L For the scope in which they are declared
V Lexical scope
LO Stack
LI No linkage
2.Static data inside a function
C First time when control hits the definition
D When the program exits normally.
L From the first time control reaches upto end of program
V Lexical scope
LO Data setcion
LI Internal
3.Non-static Global or namespace declared data
C Before the program starts
D When the program exits normally
L Throughout the program's lifetime
V Throughout the program (wherever namespace is made
available)
LO Data
LI External
4.Static global or namespace declared data
C Before the program starts
D When the program exits normally
L Throughout the program's lifetime
V In the module in which it is declared
LO Data
LI Internal
5.Temporaries
C While evaluting intermediate expressions
D When the full expression is evaluated
L Same as lifetime of the expression for which it is created
V Lexical scope of the expression
LO Stack
LI No linkage
6.Static member of a class
C When the class is instantiated for the first time.
D When the program exits normally
L From the time of creation till the end of program
V Class scope
LO Data
LI Internal linkage
7.Non static member of a class
C Every time class is instantiated
D Every time instance is destroyed
L Same as the lifetime of the instance
V Class scope
LO Same as location of instance
LI Same as linkage of the instance
8.Heap allocated data
C On calling 'new'
D On calling delete
L From explicit creation upto explict deletion or end of program
V Same as the visibility of the pointer pointing to the heap memory
LO Heap
LI Same as the linkage of the pointer pointing to heap memory.
-----------------------------------------------------------------------------------------
I was just listing down various ways in which variables can be created
and destroyed in C++. (On the lines of 10.4.3 TC++PL Ed 3)
Putting the summary here for corrections, comments, criticism, advices,
improvements.
Abbreviation:
Created (C)
Destroyed (D)
Lifetime (L)
Visibility (V)
Location (Lo)
Linkage (Li)
----------------------------
1.Local data inside a function
C When control hits the definition
D At the end of scope
L For the scope in which they are declared
V Lexical scope
LO Stack
LI No linkage
2.Static data inside a function
C First time when control hits the definition
D When the program exits normally.
L From the first time control reaches upto end of program
V Lexical scope
LO Data setcion
LI Internal
3.Non-static Global or namespace declared data
C Before the program starts
D When the program exits normally
L Throughout the program's lifetime
V Throughout the program (wherever namespace is made
available)
LO Data
LI External
4.Static global or namespace declared data
C Before the program starts
D When the program exits normally
L Throughout the program's lifetime
V In the module in which it is declared
LO Data
LI Internal
5.Temporaries
C While evaluting intermediate expressions
D When the full expression is evaluated
L Same as lifetime of the expression for which it is created
V Lexical scope of the expression
LO Stack
LI No linkage
6.Static member of a class
C When the class is instantiated for the first time.
D When the program exits normally
L From the time of creation till the end of program
V Class scope
LO Data
LI Internal linkage
7.Non static member of a class
C Every time class is instantiated
D Every time instance is destroyed
L Same as the lifetime of the instance
V Class scope
LO Same as location of instance
LI Same as linkage of the instance
8.Heap allocated data
C On calling 'new'
D On calling delete
L From explicit creation upto explict deletion or end of program
V Same as the visibility of the pointer pointing to the heap memory
LO Heap
LI Same as the linkage of the pointer pointing to heap memory.
-----------------------------------------------------------------------------------------