View
21
Download
0
Category
Preview:
DESCRIPTION
Programming In C++. Spring Semester 2013 Lecture 11. Larger Programs. Separate Compilation These files can be written, compiled separately and then linked together to form the final executable program. e.g. void main() { int a,b , ans ; printf (“Type two integers\n”); - PowerPoint PPT Presentation
Citation preview
Programming In C++
Spring Semester 2013Lecture 11
Programming In C++, Lecture 11 By Umer Rana
Larger Programs
Programming In C++, Lecture 11 By Umer Rana
Separate CompilationThese files can be written, compiled separately and then linked together to form the final executable program.e.g.void main(){
int a,b, ans;printf(“Type two integers\n”);scanf(“%d %d”, &a,&b);ans= formula(a,b);printf(“Total of two integers are: %d”, ans);
}
Larger Programs
Programming In C++, Lecture 11 By Umer Rana
Separate CompilationThese files can be written, compiled separately and then linked together to form the final executable program.e.g.int formula(int x, int y){
return (x*x + y*y);
}
Project Features
Programming In C++, Lecture 11 By Umer Rana
• The Process can either be done “by hand”, by typing command-line messages to compile each source file and to link them together or process can be turned over to a Make utility.
• Make is a program that automates the compiling and linking process. When we have a large program with dozen source files we need to compile each one, then link the resulting.obj files to create a final exe.file.
• If we change the source file, we need to recompile it and relink everything, but no need to recompile these file that haven’t changed.it is difficult to keep track of which have been compile since the last link and which haven't
Project Features
Programming In C++, Lecture 11 By Umer Rana
• Make utility keeps track of which source files must be recompiled to produce the final exe file.
• Make utility automates the whole compile and link process, so that one command suffices to perform all the steps necessary to generate the final exe file.
Advantages of Separate Compilation
Programming In C++, Lecture 11 By Umer Rana
• Compile time is proportional to the size of the file being compiled so minimize compile time.
• Programming compile only those parts of a program that have been changed since the last compilation.
• Already working & debugged are not recompile.• New file is compiled and linked with the previously
compiled files.• Enables to programmers to write well-structured
modular programs.• Separate compilation allows programmer to use library
files.
Conditional Compilation
Programming In C++, Lecture 11 By Umer Rana
• The useful facility provided by the pre-processor is conditional compilation
• The C preprocessor provides a better alternative, namely conditional compilation. Lines of source code that may be sometimes desired in the program and other times not, are surrounded by #if, # defined, #endif directive pairs as follows:
Conditional Compilation
Programming In C++, Lecture 11 By Umer Rana
#define TIMERint main (){
int j,k;#if defined(TIMER)
printf("Starting Test\n");#endif
#if defined(TIMER)printf("Ending Test\n");
#elseprintf("Done\n");
#endif
getch();}
Conditional Compilation
Programming In C++, Lecture 11 By Umer Rana
#undef Directive• This #undef Directive cancels the action of a previous #define
Directive.• This Directive to make conditional compilation specific to certain
sections of the program.• Another use for #undef is to “turn off” macros that you have
previously defined with a #define directive.e.g.
#define TEST
#undef TEST
Recommended