1 / 10

Principles of Scientific Programming

Principles of Scientific Programming. Tarik Roukny Yves Dominici. C++ and Software Programming. Chapter 6 : Source Files. Outline. Chap 1 – Introduction Chap 2 – Compiler and Memory Chap 3 – Types Chap 4 – Control Structures Chap 5 – Functions Chap 6 – Source Files

finn-bowman
Download Presentation

Principles of Scientific Programming

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. Principles of Scientific Programming Tarik Roukny Yves Dominici

  2. C++ and Software Programming Chapter 6 : Source Files

  3. Outline • Chap 1 – Introduction • Chap 2 – Compiler and Memory • Chap 3 – Types • Chap 4 – Control Structures • Chap 5 – Functions • Chap 6 – Source Files • Chap 7 – Classes and Objects

  4. Multiple Compiling • Issue: • Programs can easily become series of very long lines of code • Separate the code in several files = modules • Advantage: • More easy to read • More flexible and extensible • Every modification only calls for the compiling of one file • Disadvantage: • Compiler needs to map all information • Need to be rigorous in the methodology

  5. Multiple Compiling • The compiling process can now be separated in two steps • Compile code generation for each source code taken separately • Link editing In order to allow communication between the different parts/modules of the program

  6. Multiple Compiling • Idea • Code separeted in several files (‘.cpp’) file1.cpp file2.cpp file3.cpp • Compile each file independently g++ -c file1 file1.cpp g++ -c file2 file2.cpp g++ -c file3 file3.cpp • Edit the links g++ -o finalProgram file1.o file2.o file3.o

  7. Multiple Compiling • Design the structure w.r.t. to the logic of the program • 1 file for each specific tasks –module • 1 file for the main

  8. Headers “.h” • How to communicate the link between the files: • Headers : files with ending “.h” • Import the information via : #include “headerName.h” • Simple copy-paste of the file • Like when importing a library • The header contains: • Declaration of functions accessible from the other modules • Definition of types used in the module module1.h #include “module1.h” #include “module1.h” module1.cpp main.cpp

  9. Multiple includes • A header can include other headers • Problem • If a header includes a header that is including a header that includes the first header, etc. • Solution • Start with #ifndef NAME #define NAME • End with #endif /*NAME*?

  10. 10 Exercise: ATM Example No Yes No Yes No Yes • Extension: • Modularize using several files Yes No 11/8/2014

More Related