1 / 9

Programming In C++

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<br>”);

aidan-king
Download Presentation

Programming In C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming In C++ Spring Semester 2013 Lecture 11 Programming In C++, Lecture 11 By Umer Rana

  2. 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() { inta,b, ans; printf(“Type two integers\n”); scanf(“%d %d”, &a,&b); ans= formula(a,b); printf(“Total of two integers are: %d”, ans); } Programming In C++, Lecture 11 By Umer Rana

  3. Larger Programs Separate Compilation These 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); } Programming In C++, Lecture 11 By Umer Rana

  4. Project Features 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 Programming In C++, Lecture 11 By Umer Rana

  5. Project Features Make utility keeps track of which source files must be recompiled to produce the final exe file. Makeutility automates the whole compile and link process, so that one command suffices to perform all the steps necessary to generate the final exe file. Programming In C++, Lecture 11 By Umer Rana

  6. Advantages of Separate Compilation 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. Programming In C++, Lecture 11 By Umer Rana

  7. Conditional Compilation 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: Programming In C++, Lecture 11 By Umer Rana

  8. Conditional Compilation #define TIMER int main () { intj,k; #if defined(TIMER) printf("Starting Test\n"); #endif #if defined(TIMER) printf("Ending Test\n"); #else printf("Done\n"); #endif getch(); } Programming In C++, Lecture 11 By Umer Rana

  9. Conditional Compilation #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 #undefis to “turn off” macros that you have previously defined with a #define directive. e.g. #define TEST #undef TEST Programming In C++, Lecture 11 By Umer Rana

More Related