At this course point, you probably already have created one or many variables on your programs a long of the computer science course. Nevertheless, many computer science students still didn't realize the true meaning of that, just know that they are there. The goal of this exercise if to cast some light on the subject by snooping in the "Where is My Variable?" program life-cycle.
Let's begin with Where is My Variable's source code (where.cc):
1. |
int a; |
This program declares in various variable and constant forms.
Simple, very simple!
Now let's take a look at the compilation process for "Where is My Variable". For the upcoming discussion, we'll take the widely-used GNU compiler (g++) and its associated tools (binutils). We can compile the program as follows:
# g++ -O0 -c where.ccThis produces the object file where.o. More specifically,
# file where.otells us where.o is a relocatable object file, compiled for the IA-32 architecture (I used a standard PC for this study), that contains a symbol table (not stripped).
By the way,
# objdump -hrt where.otells us where.o has 5 sections:
Let's take a look at the assembly code:
1. |
# g++ -Os -S where.cc -o -
|
Tells us: