Discussion Week 1. TA: Kyle Dewey. Sunday, September 25, 11

Similar documents
Memory Leak. C++: Memory Problems. Memory Leak. Memory Leak. Pointer Ownership. Memory Leak

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

Common Misunderstandings from Exam 1 Material

StackVsHeap SPL/2010 SPL/20

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

EL2310 Scientific Programming

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

CS3215. Outline: 1. Introduction 2. C++ language features 3. C++ program organization

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

Makefiles SE 2XA3. Term I, 2018/19

CS64 Week 5 Lecture 1. Kyle Dewey

C++ Object-Oriented Programming

CSE 333 Midterm Exam 5/9/14 Sample Solution

10. Abstract Data Types

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

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

OBJECT ORIENTED PROGRAMMING USING C++

Object-Oriented Programming

CMSC 132: Object-Oriented Programming II

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Lecture 15: Object-Oriented Programming

Implementing Subprograms

CMSC 132: Object-Oriented Programming II

Pointers. Developed By Ms. K.M.Sanghavi

CSE 303: Concepts and Tools for Software Development

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

And Even More and More C++ Fundamentals of Computer Science

COMP26912: Algorithms and Imperative Programming

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Slide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Chapter 11. Abstract Data Types and Encapsulation Concepts

Introduction to Programming Using Java (98-388)

CSCI-1200 Data Structures Fall 2011 Lecture 24 Garbage Collection & Smart Pointers

eingebetteter Systeme

Programming overview

Inheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization

Abstract Data Types and Encapsulation Concepts

Introduction to Object-Oriented Programming

Praktikum: Entwicklung interaktiver eingebetteter Systeme

CSCI-1200 Data Structures Spring 2017 Lecture 27 Garbage Collection & Smart Pointers

C++ 8. Constructors and Destructors

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Introducing C++ to Java Programmers

CS250 Final Review Questions

C10: Garbage Collection and Constructors

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Object Oriented Design

A Fast Review of C Essentials Part II

Programming Languages & Paradigms PROP HT Course Council. Subprograms. Meeting on friday! Subprograms, abstractions, encapsulation, ADT

Project. C++: Smart Pointers. The Plan. Announcement. Memory Leak. Pointer Ownership. Today: STL 1 Wednesday: STL 2 Thursday: Smart Pointers

Reviewing gcc, make, gdb, and Linux Editors 1

INHERITANCE: CONSTRUCTORS,

SISTEMI EMBEDDED. Stack, Subroutine, Parameter Passing C Storage Classes and Scope. Federico Baronti Last version:

CS250 Final Review Questions

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates

Lecture 13: more class, C++ memory management

Data Abstraction. Hwansoo Han

CS240: Programming in C

Introduction to Java

G Programming Languages - Fall 2012

AN OVERVIEW OF C++ 1

Intermediate Programming, Spring 2017*

EL2310 Scientific Programming

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Lecture 15a Persistent Memory & Shared Pointers

Praktische Aspekte der Informatik

Packages Inner Classes

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Programming II (CS300)

CPSC 427: Object-Oriented Programming

Part VII. Object-Oriented Programming. Philip Blakely (LSC) C++ Introduction 194 / 370

TDDE18 & 726G77. Functions

CS240: Programming in C

EL2310 Scientific Programming

CS24 Week 3 Lecture 1

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN

Special Member Functions

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

Chapter 11. Abstract Data Types and Encapsulation Concepts 抽象数据类型 与封装结构. 孟小亮 Xiaoliang MENG, 答疑 ISBN

Ministry of Higher Education Colleges of Applied Sciences Final Exam Academic Year 2009/2010. Student s Name

Interview Questions of C++

Implementing Abstractions

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

Programming, numerics and optimization

Chapter 1 Getting Started

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Chapter 6 Introduction to Defining Classes

CMSC 4023 Chapter 11

CS Basics 15) Compiling a C prog.

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009

C++ for System Developers with Design Pattern

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

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSE 12 Week Eight, Lecture One

Transcription:

Discussion Week 1 TA: Kyle Dewey

Project 0 Walkthrough

Makefiles

What? A programmable command that can generate new files based on existing ones Only that which is needed is made main.c main.o a.out helpers.h helpers.o helpers.c

Why? The standard gcc *.c or javac *.java scales poorly Everything recompiled Cannot handle directory hierarchy Arbitrary builds may need an arbitrary sequence of commands

Basics Makefiles consist of a series of rules Each rule has optional dependencies The first rule is the default rule_name: target1 target2 how to build output

Basics Dependencies can be either rule names or file names The process recursively follows dependencies

Macros Macros can be used to define common strings and utilities MACRO_NAME = definition

Example

Including Makefiles can reference other makefiles Common rules Common macros include../makefile

NACHOS Makefiles

C++ as it applies to NACHOS

Recommendation c++.pdf in the c++example directory is an excellent tutorial A bit dated, but applicable to NACHOS

What is Not Seen Templates Polymorphism Inheritance References

Header Files #ifndef FILE_H #define FILE_H // code /* more code * some more code */ #endif

Class Definition class MyClass { public: MyClass(); int dosomething( int x ); private: int privatefunction(); int privatevariable; };

Class Definition Generally, class definition should be done in header file The header file defines the interface to the class

Class Implementation Classes should generally be implemented in C++ code files (.cpp,.c++,.cc...) NACHOS uses the.cc extension

Class Implementation Example #include MyClass.cc MyClass::MyClass() : privatevariable( 5 ) {} int MyClass::doSomething( int x ) { return x + 1; } int MyClass::privateFunction() { return privatevariable * 2; }

Memory Management C++ lacks a garbage collector Classes have user-defined destructors that specify how to perform such cleanup Destructor for MyClass has the method signature ~MyClass()

Instantiating a Class On the stack: MyClass foo( 5 ); On the stack (no-arg constructor): MyClass foo; On the heap: MyClass* foo = new MyClass( 5 ); MyClass* foo = new MyClass();

Destructing an Instance On the stack, once a class goes out of scope, the destructor is automatically called On the heap: delete foo; foo is a pointer to the class instance

Instantiating an Array On the stack: int foo[ 5 ]; int foo[] = { 0, 1, 2, 3, 4 }; On the heap: int* foo = new int[ 5 ];

Destructing an Array Performed automatically for once out of scope for arrays on the stack On the heap: delete[] myarray; myarray is a pointer to the array

Destructing an Array There is only a single dimensional delete[] operator For a two dimensional array myarray of size size : for( int x = 0; x < size; x++ ) { delete[] myarray[ x ]; } delete[] myarray;

code/threads/list Example from NACHOS

Assembly (Time Permitting)

Registers Programs need to use processor registers in order to execute

Registers Process #100 Process #101 Register Value Register Value A 1 B 2 C 3 A 30 B 40 C 50

Swapping In State of registers is copied from memory to the registers Process resumes execution with the restored register values

Swapping Out The process execution is paused The values of the registers is saved to memory

Unportable The need to deal directly with registers prevents the usage of portable, high-level language code Assembly must be used

switch.s