Discussion Week 1 TA: Kyle Dewey. Project 0 Walkthrough.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

1.00 Lecture 37 A Brief Look at C++: A Guide to Reading C++ Programs.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CSSE 332 Standard Library, Storage classes, and Make.
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
CS 225 Lab #2 - Pointers, Copy Constructors, Destructors, and DDD.
Guide To UNIX Using Linux Third Edition
CS-2303 System Programming Concepts
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
OOP Languages: Java vs C++
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Introduction to C++. Overview C++? What are references Object orientation Classes Access specifiers Constructor/destructor Interface-implementation separation.
Programming Languages and Paradigms Object-Oriented Programming.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
The Rest of the Story.  Constructors  Compiler-generated  The Initializer List  Copy Constructors  Single-arg (conversion ctors)  The Assignment.
Intro to C++ And Some Tools Opening Discussion zHave any questions come up since last class? Have you had a chance to look over the project.
SPL/2010 StackVsHeap. SPL/2010 Objectives ● Memory management ● central shared resource in multiprocessing RTE ● memory models that are used in Java and.
By – Tanvir Alam.  This tutorial offers several things.  You’ll see some neat features of the language.  You’ll learn the right things to google. 
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Programming in Java CSCI-2220 Object Oriented Programming.
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
Week 2-3 Control flow (review) Conditional statements If, else, else if, switch-case, break Loop constructs for, while, do-while, break, continue, label--go;
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Session 7 Methods Strings Constructors this Inheritance.
Object-Based Programming Mostly Review. Objects Review what is object? class? member variables? member functions? public members? private members? friend.
0 4.1 Basics of Functions + Execution Diagram + make 4.2 Functions Returning Non-integers + Prototype Function 4.3 External Variables 4.4 Scope Rules 4.5.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Data Display Debugger (DDD)
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
C++ Functions A bit of review (things we’ve covered so far)
Memory Management in Java Mr. Gerb Computer Science 4.
Lecture 3 Translation.
Chapter 2 Objects and Classes
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Classes C++ representation of an object
Java Yingcai Xiao.
C++ Object-Oriented Programming
Lecture 2 Memory management.
C Basics.
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Dynamic Memory Management
Classes C++ representation of an object
Dynamic Memory Management
SPL – PS3 C++ Classes.
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

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 helpers.h helpers.c main.o helpers.o a.out

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

Example helpers.o : helpers.c helpers.h gcc -c helpers.c main.o : main.c gcc -c main.c a.out : helpers.o main.o gcc helpers.o main.o

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 RegisterValue A1 B2 C3 Process #101 RegisterValue A30 B40 C50

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