Question? Leave a message!




C/C++ Programming

C/C++ Programming
Dr.MasonHanks Profile Pic
Dr.MasonHanks,Germany,Teacher
Published Date:23-07-2017
Website URL
Comment
CIS 190: C/C++ Programming Lecture 2 Not So Basics 1 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 2 What is Separate Compilation? 3 Why Use Separate Compilation? • organize code into collections of smaller files that can be compiled individually • can separate based on: – a user-made “library” (e.g., math functions) – related tasks (e.g., functions for handling a data structure) – sub-parts of the program (e.g., reading user input) 4 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() ... void PrintTrain(...) ... void AddTrainCar(...) ... hw2.c 5 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 6 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 7 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 8 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 9 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 10 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 11 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 12 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 13 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 14 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 15 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... include “trains.h” hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 16 Example: Homework 2 Files include “trains.h” void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... include “trains.h” hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 17 Example: Homework 2 Files include “trains.h” void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... include “trains.h” hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 18 Separate Compilation • need to include “fileName.h” at top of any .c file using the functions prototypes inside that .h file • for local files we use quotes “filename.h” • for libraries we use carats stdio.h 19 Separate Compilation • after a program is broken into multiple files, the individual files must be: – compiled separately • using gcc and the –c flag – linked together • using gcc and the created .o (object) files 20