A C program can have the following kinds of variables. 1) Global variables: a) default global variables i) initialized ii) uninitialized b) static global variables i) initialized ii) uninitialized c) external global variables 2) Local variables: a) automatic local variables i) initialized ii) uninitialized b) static local variables i) initialized ii) uninitialized c) formal parameters d) external local variables 3) Dynamic variables NOTE: For each of the above kinds of variables, you should be able to specify its scope and its lifetime. ------------------------------------------------------------------------ A running C program is made up of the following parts. 1) Code: a) your code b) library code c) operating system code 2) Data: a) initialized data segment b) uninitialized data segment c) read-only data segment d) stack e) heap NOTE: Each kind of C variable mentioned in the first part is stored in one of the 5 data areas listed just above. You should be able to specify which kind of variable is stored in which kind of data area. ------------------------------------------------------------------------- Here are the steps involved in converting a C source code file into a running program. Along with each step is listed some tools that you can use to observe the result of that step. Using these tools, you can take a simple C program and observe into which data area listed above each of the kinds of variables listed in the first part above gets stored. C Source Code -------> text editor | | | Compiler | | Assembly Source Code --> text editor | | | Assembler | | obj file ---------> Dumpbin (comes with Visual Studio) | PEview (www.magma.ca/~wjr/) | PE Dump (comes with LCC-Win32) | | Linker | | exe file ---------> Depends (www.dependencywalker.com) | PEBrowse (www.smidgeonsoft.com) | Dumpbin | PEview | PE Dump | Loader | | runtime image ------> Visual Studio debugger Process Viewer (www.prcview.com) Process Explorer (www.sysinternals.com) PEBrowseDbg (www.smidgeonsoft.com) Process Walker (from MS Platform SDK Examples) API Monitor (www.rohitab.com) NOTE: One interesting thing to note is that at every step of the above process you can use at least one of the tools listed to get an "assembly language" listing of the result of that step. Take a simple program, look at its assembly language at each of these steps and notice how the assembly language is modified a bit at each step. In particular, each step resolves more symbols into addresses than the previous step. -------------------------------------------------------------------------------- Here are some command line tools (given in TextPad's syntax) that let you implement the steps described above. Tools are given for the Lcc-Win32, MinGW, and Microsoft Visual Studio 6 compilers. To compile a C program and get its assembly language listing, use the following command lines. In each case, the compiler will produce an object file with the extension "obj" and the assembly language listing will be put in a file with the extension "asm". lcc -c -g2 -S $File gcc -c -g -Wall -fverbose-asm -Wa,-a,-adhlns=$BaseName.asm -o $BaseName.obj $File cl /c /Od /Zi /W1 /nologo /FAsc /Fa$BaseName.asm /MDd $File To look at the assembly language listing contained in the obj file (which will not be quite the same as the assembly language listing produced by the compiler) use the following commands with lcc, gcc, and cl respectively. pedump /A $BaseName.obj objdump -S -t $Basename.obj dumpbin /DISASM /SYMBOLS $BaseName.obj To link the obj file and produce an exe file, use the following commands. lcclnk -subsystem console $BaseName.obj gcc -Wall -g -o $BaseName.exe $BaseName.obj link $BaseName.obj To look at the assembly language listing contained in the exe file use the following commands with lcc, gcc, and cl respectively. pedump /A $BaseName.exe objdump -S -t $Basename.exe dumpbin /DISASM $BaseName.exe NOTE: To use the Microsoft VS 6 command lines in a cmd.exe shell, you need to execute the VCVARS32.BAT batch file first (unless you have the proper registry keys set and I do not know which keys these are). Here is an abbreviated version of that batch file that works with Windows XP. @echo off set VSCommonDir=C:\cs302\Microsoft Visual Studio 6\Common set MSDevDir=C:\cs302\Microsoft Visual Studio 6\Common\msdev98 set MSVCDir=C:\cs302\Microsoft Visual Studio 6\VC98 set PATH=%MSVCDir%\BIN;%MSDevDir%\BIN;%VSCommonDir%\TOOLS\WINNT;%VSCommonDir%\TOOLS;%PATH% set INCLUDE=%MSVCDir%\ATL\INCLUDE;%MSVCDir%\INCLUDE;%MSVCDir%\MFC\INCLUDE;%INCLUDE% set LIB=%MSVCDir%\LIB;%MSVCDir%\MFC\LIB;%LIB%