before we start
play

Before we start Any questions on UML from last week? C++: - PDF document

Before we start Any questions on UML from last week? C++: Architecture and Conventions History of C++ History of C++ 1969 UNIX Why bring this up Created to play space wars C is a low level system language


  1. Before we start • Any questions on UML from last week? C++: Architecture and Conventions History of C++ History of C++ • 1969 – UNIX • Why bring this up – Created to play space wars – C is a “low level” system language – B (Basic Combined Programming Language) • Program as manipulator of memory • 1970 • All memory management done by hand – UNIX port to PDP-11 – C++ is not only based on C but is a proper • 1972 superset – C (rewrite of B) • If you can do it in C you can do it in C++ • Early 1980s • Added Object Oriented paradigm. – Take home message: C++ is not Java!!!! – C++ invented as a “superset of C” File Structure File Structure • One class, two files • Cpp – The C Preprocessor – Header file (.h) – Reads all C code before compilation • Contains class declaration (interface++) – Directives – Source file (.c, .cpp, .C, .cxx) • Including text files • Contains class definition – #include • Conditional compilation – implementation of methods – #if / #ifdef / #ifndef / #else / #endif • Macros – #define

  2. File Structure Compilation – Java Other Java classes • #include “filename.h” – Inserts text from one file into another before Foo.java javac Foo.class compilation java Foo Foo.java – Contain info needed by other files to compile JVM • Libraries – function signature (platform Java • Classes – class interface (I.e. header file) independent) (platform compiler dependent) Compilation – C++ Compilation – Java vs C++ Other object linked • Java • C++ Foo.C – Compilation unit is the – Compilation unit is the Foo.o CC foo.o .. class file CC Foo.C – External classes – External classes located using a require header and Foo.exe Object file predefined path precompiled object file linking Foo.h C++ (platform – JVM needed to execute – Executable file need to compiler dependent) execute. Executable file (platform dependent) Compilation – C++ Using C Libraries • Use CC to compile individual files into • Like Java, C/C++ has a multitude of useful object files auxillary functions and classes in libraries • Use CC to link object files into an • Unlike Java, C++ does not have the notion executable file of packages. – Need to specify executable name, otherwise • C / C++ also doesn’t have nice javadocs will be named a.out • Use man instead • Run the executable file.

  3. Using C Libraries Managing C++ Projects • Library header files must be #included for • make compilation – Files to be compiled – Compiler options – #include “mylib.h” – Libraries – #include <math.h> – Dependencies • Library object files must be linked when linking. – Make will build an executable – makemake – Makes Makefiles! – CC file file file –lm mylib.o – Lab 3 Running C++ Executables Anatomy of a class • No top level “main” class • Let’s take a look at a header and source file – main() in its own file for a C++ class, shall we? – main (char *argv[], int argc) • If there is a problem… – Bus error (core dumped) – Segmentation fault (core dumped) • Questions? Anatomy of a class • Things to remember – .h & .C files – No package, but namespaces – C++ Style guidelines – Comment, comment, comment • Questions?

Recommend


More recommend