INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

Similar documents
CSC 2500: Unix Lab Fall 2016

CS2141 Software Development using C/C++ Compiling a C++ Program

Projects and Make Files

Final Topics. Ali Malik

CS Basics 15) Compiling a C prog.

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

CS 247: Software Engineering Principles. Modules

2 Compiling a C program

Build automation. CSE260, Computer Science B: Honors Stony Brook University

And You Thought There Couldn t be More C++ Fundamentals of Computer Science

Laboratorio di Tecnologie dell'informazione

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Separate Compilation of Multi-File Programs

The Linux Programming Environment. Computer Science Department Texas State University

Intermediate Programming, Spring 2017*

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

Laboratorio di Programmazione. Prof. Marco Bertini

CAAM 420 Fall 2012 Lecture 15. Roman Schutski

The University Of Michigan. EECS402 Lecture 09. Andrew M. Morgan. Savitch Ch Compiling With Multiple Files Make Utility.

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Compiling and Linking

CS201 - Introduction to Programming Glossary By

CS 107 Lecture 18: GCC and Make

PROGRAM COMPILATION MAKEFILES. Problem Solving with Computers-I

CMPSC 311- Introduction to Systems Programming Module: Build Processing

C / C++ Coding Rules

Short Notes of CS201

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Part III Synchronization A bit of C++ and ThreadMentor

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

COMP Lecture Notes The Compiler

independent compilation and Make

Software Engineering /48

CS240: Programming in C

Lecture 2: C Programming Basic

CPSC 427: Object-Oriented Programming

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Laboratorio di Programmazione. Prof. Marco Bertini

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

Makefiles SE 2XA3. Term I, 2018/19

CSI33 Data Structures

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Chapter 2. Lexical Elements & Operators

Starting to Program in C++ (Basics & I/O)

C++ Programming for Non-C Programmers. Supplement

The Compilation Process

Lab 1: First Steps in C++ - Eclipse

1.1 The hand written header file

Compilation, Disassembly, and Profiling (in Linux)

Cpt S 122 Data Structures. Introduction to C++ Part II

What is Class? Remember

Full file at C How to Program, 6/e Multiple Choice Test Bank

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

ENERGY 211 / CME 211. Evolution

Reviewing gcc, make, gdb, and Linux Editors 1

Chris' Makefile Tutorial

Programming in C S c o t t S c h r e m m e r

Maemo Diablo GNU Make and makefiles Training Material

How Compiling and Compilers Work

UNIX Makefile. C Project Library Distribution and Installation.

Makefile Tutorial. Eric S. Missimer. December 6, 2013

PRINCIPLES OF OPERATING SYSTEMS

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

INDEX. Figure I-0. Listing I-0. Table I-0. Symbols.DIRECTIVE (see Assembler directives)? preprocessor operator 3-34

Laboratorio di Programmazione. Prof. Marco Bertini

JTSK Programming in C II C-Lab II. Lecture 3 & 4

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

PROGRAMMAZIONE I A.A. 2017/2018

Chapter 11 Introduction to Programming in C

Outline. COMP 2718: Software Development Tools: gcc and make. C and Java 3/28/16

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Crash Course in C++ R F L Evans. www-users.york.ac.uk/~rfle500/

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

Have examined process Creating program Have developed program Written in C Source code

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

A Fast Review of C Essentials Part II

M2 Instruction Set Architecture

OBJECT ORIENTED PROGRAMMING USING C++

Computer Systems Lecture 9

The make utility. Alark Joshi COMPSCI 253

CS11 Advanced C++ Fall Lecture 4

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C

Executables and Linking. CS449 Spring 2016

The C Preprocessor (and more)!

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Lecture 4. Default Arguments. Set defaults in function prototype. int myfunction( int x = 1, int y = 2, int z = 3 );

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

C++ Coding Standards and Practices. Tim Beaudet March 23rd 2015

What s next. Computer Systems A Programmer s Perspective

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

Multiple file project management & Makefile

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

CMPT 300. Operating Systems. Brief Intro to UNIX and C

C++ Inheritance and Encapsulation

Command Line Navigation and Compiling

fpp: Fortran preprocessor March 9, 2009

Transcription:

HEADER FILE A header (.h,.hpp,...) file contains Class definitions ( class X {... }; ) Inline function definitions ( inline int get_x() {... } ) Function declarations ( void help(); ) Object declarations ( extern int debug_enabled; ) CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 Makefile, compiler,.h and.cpp files These files allow programmers to separate certain elements of a program's source into reusable files. Header files commonly contain forward declarations of classes, variables, and other identifiers. A header file might be included by more than one CPP file. This is to keep the interface in the header separate from the implementation. 2 SOURCE FILE A source file (.c,.cpp,.cxx) contains Function definitions ( void help() { }, void X::f() { } ) Object definitions ( int debug_enabled = 1; ) ACCESS SPECIFIER: PUBLIC, PRIVATE, PROTECTED Any data declared private inside a class is not accessible from outside the class. By default, all data are private. Source files will contain definitions that must be present only once in the whole program. A CPP file includes the definitions from any header which it includes (because CPP and header file together become a single 'translation unit') 3 Specifying that a data member or member function is public means that it can be accessed from anywhere in your. Making a data member or member function protected means that it can only be accessed from within the class or a subclass. 4 1

FRIEND AND INLINE FUNCTIONS If we want to allow an external function to have access to the private and protected, we declare a prototype of this external function within the class and precede it with the keyword friend. An inline function is a function that the compiler has been requested to perform inline expansion upon. Inline expansion is used to eliminate the time overhead when a function is called. It is typically used for functions that execute frequently. 5 EXAMPLE : COMPLEX CLASS Complex.h Complex.cpp Driver.cpp Makefile.txt 6 Line Splicing Lines continued with escaped newline are spliced to form logical lines. g++ Tokenization The preprocessor breaks the result into preprocessing tokens and whitespace. It replaces comments with whitespace. Expand the macros Manage the #ifndef Manage the #define Replace all the #include 7 #= # 8 2

Translate to assembly language, a symbolic representation of the binary machine s Translate assembly language to binary machine s, leaving the addresses of external functions undefined MOV XOR JMP 9 MOV XOR JMP? 10 Create the final executable from all the object files by replacing the unknown addresses by their actual? 1110.c.i.s.o Source Preprocessor Compiler Assembler Linker Preprocessed Language Machine (Object File).out.exe Final 1110 11 12 3

You can use g++ both to compile programs into object modules and to link these object modules together into a single program. 2 steps 1/ compilation g++ -c compile-options file.cpp 2/ linking g++ -o progname link-options file1.o file2.o... You can bunch these two steps - compilation and linking - into one with the following command. g++ -o progname compile-and-link-options file1.cpp file2.cpp... 13 Options -c ( option) Compile only. Produces.o files from source files without doing any linking. -o file-name (Link option) Use file-name as the name of the file produced by g++ (usually, this is an executable file). -g ( and link option) Put debugging information for gdb into the object or executable file. Should be specified for both compilation and linking. -Wall ( option) Produce warning messages about a number of things that are legal but dubious. I strongly suggest that you always specify this and that you treat every warning as an error to be fixed. 14 MAKEFILE The basic makefile is composed of: target: dependencies [tab] system command In our Complex example, it would look like all: g++ -g Wall Driver.cpp Complex.cpp -o 15 MAKEFILE The make utility will execute the first target if no other one is specified. Sometimes is useful to use different targets (if you modify a single file in your project, you don't have to recompile everything, only what you modified) all: hello hello: main.o factorial.o hello.o g++ main.o factorial.o hello.o -o hello main.o: main.cpp g++ -c main.cpp factorial.o: factorial.cpp g++ -c factorial.cpp hello.o: hello.cpp g++ -c hello.cpp clean: rm -rf *o hello 16 4

MAKEFILE You can also use variables when writing Makefiles. It comes in handy in situations where you want to change the compiler, or the compiler options. CC=g++ CFLAGS=-c -Wall all: hello hello: main.o factorial.o hello.o $(CC) main.o factorial.o hello.o -o hello MAKEFILE : EXAMPLE Makefile.txt main.o: main.cpp $(CC) $(CFLAGS) main.cpp factorial.o: factorial.cpp $(CC) $(CFLAGS) factorial.cpp hello.o: hello.cpp $(CC) $(CFLAGS) hello.cpp clean: rm -rf *o hello 17 18 5