Monday, September 19, 2011

Compilation Process of a C++ Program




Compiling a C++ program involves a number of steps (most of which are
transparent to the user):

· First, the C++ preprocessor goes over the program text and carries out theinstructions specified by the preprocessor directives (e.g., #include). The result is a modified program text which no longer contains any directives.

· Then, the C++ compiler translates the program code. The compiler may be a true C++ compiler which generates native (assembly or machine) code, or just a translator which translates the code into C. In the latter case, the resulting C code is then passed through a C compiler to produce native object code. In either case, the outcome may be incomplete due to the program referring to library routines which are not defined as a part of the program. For example, Listing 1.1 refers to the << operator which is actually defined in a separate IO library.


· Finally, the linker completes the object code by linking it with the object code of any library modules that the program may have referred to. The final result is an executable file.


In the following  Figure,  illustrates the above steps for both a C++ translator and a C++ native compiler. In practice all these steps are usually invoked by a single command (e.g. CC) and the user will not even see the intermediate files generated.


4 comments em “Compilation Process of a C++ Program”

Post a Comment

Give your valuable Comment...

 

Programming, Data Structures & Algorithms Copyright © 2011 -- Template created by JAK -- Powered by Blogger