Apr 5, 2009

C++ Program Development Phases [note on C++ How to Program - 02]

C++ programs typically go through six phases: edit, preprocess, compile, link, load and execute.

CPP program development phases 

Preprocessing and compiling

In phase 2, the programmer gives the command to compile the program. In a C++ system, a preprocessor program executes automatically before the compiler's translation phase begins (so we call preprocessing phase 2 and compiling phase 3). The C++ preprocessor obeys commands called preprocessor directives, which indicate that certain manipulations are to be performed on the program before compilation. These manipulations usually include other text files to be compiled and perform various text replacements. In phase 3, the compiler translates the C++ program into machine-language code (also referred to as object code).

Preprocessing occurs before a program is compiled. Some possible actions are inclusion of other files in the file being compiled, definition of symbolic constants and macros, conditional compilation of program code and conditional execution of preprocessor directives. All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not C++ statements, so they do not end in a semicolon (;). Preprocessor directives are processed fully before compilation begins.

The formats of preprocessor directives are described as above. There are several kinds of preprocessor directives, like the #include preprocessor directive and the #define preprocessor directive.

Linking

Phase 4 is called linking. C++ programs typically contain references to functions and data defined elsewhere, such as in the standard libraries or in the private libraries of groups of programmers working on a particular project. The object code produced by the C++ compiler typically contains "holes" due to these missing parts. A linker links the object code with the code for the missing functions to produce an executable image (with no missing pieces). If the program compiles and links correctly, an executable image is produced.


Comments

Every program should begin with a comment that describes the purpose of the program, author, date and time.

Besides the normal comments dedicated to the methods, variables, or certain lines of codes, we should also add comments at the top of the source code describing the purpose, author, date of the program. Without these, you may totally donot know what the program is about when you revisit it after a long time. I ever experienced this embrassing scenarios, so I will keep this in mind from now on.

2 comments: