# Tail call elimination. Michel Schinz

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Tail call elimination Michel Schinz

2 Tail calls and their elimination

3 Loops in functional languages Several functional programming languages do not have an explicit looping statement. Instead, programmers resort to recursion to loop. For example, the central loop of a Web server written in Scheme might look like this: (define web-server-loop (lambda () (wait-for-connection) (fork handle-connection) (web-server-loop))) 3

4 The problem Unfortunately, recursion is not equivalent to the looping statements usually found in imperative languages: recursive function calls, like all calls, consume stack space while loops do not... In our example, this means that the Web sever will eventually crash because of a stack overflow this is clearly unacceptable! A solution to this problem must be found... 4

5 The solution In our example, it is obvious that the recursive call to webserver-loop could be replaced by a jump to the beginning of the function. If the compiler could detect this case and replace the call by a jump, our problem would be solved! This is the idea behind tail call elimination. 5

6 Tail calls The reason why the recursive call of web-server-loop could be replaced by a jump is that it is the last action taken by the function : (define web-server-loop (lambda () (wait-for-connection) (fork handle-connection) (web-server-loop))) Calls in terminal position like this one are called tail calls. This particular tail call also happens to target the function in which it is defined. It is therefore said to be a recursive tail call. 6

7 Tail calls examples In the functions below, all calls are underlined. Which ones are tail calls? (define map (lambda (f l) (if (null? l) l (cons (f (car l)) tail call (map f (cdr l)))))) (define fold (lambda (f z l) (if (null? l) z (fold f (f z (car l)) (cdr l))))) recursive tail call 7

8 Tail call elimination When a function performs a tail call, its own activation frame is dead, as by definition nothing follows the tail call. Therefore, it is possible to first free the activation frame of a function about to perform such a call, then load the parameters for the call, and finally jump to the function s code. This technique is called tail call elimination (or optimisation), abbreviated TCE. 8

9 TCE example Consider the following function definition and call: (define sum (lambda (z l) (if (null? l) z (sum (+ z (car l)) (cdr l))))) (sum 0 (list )) How does the stack evolve, with and without tail call elimination? 9

10 TCE example Without tail call elimination, each recursive call to sum makes the stack grow, to accommodate activation frames (1 2 3) (1 2 3) (1 2 3) (1 2 3) (2 3) (2 3) (2 3) 3 3 (3) (3) time 6 () 10

11 TCE example With tail call elimination, the dead activation frames are freed before the tail call, resulting in a stack of constant size (1 2 3) (2 3) (3) () time 11

12 Tail call optimisation? Tail call elimination is more than just an optimisation! Without it, writing a program that loops endlessly using recursion and does not produce a stack overflow is simply impossible. For that reason, full tail call elimination is actually required in some languages, e.g. Scheme. In other languages, like C, it is simply an optimisation performed by some compilers in some cases. 12

13 Tail call elimination for minischeme

15 Implementing TCE Tail call elimination is implemented by: 1. identifying tail calls in the program, 2. compiling those tail calls specially, by deallocating the activation frame of the caller before jumping to the called function. We already know how to compile tail calls, but we did not explain yet how to identify them. 15

16 Identifying tail calls To identify tail calls, we first assume that all calls are marked with a unique number. We then define a function T that returns the marks corresponding to the tail calls. For example, given the following expression: (lambda (x) (if 1 (even? x) 2 (g 3 (h x)) 4 (h 5 (g x)))) T produces the set { 2,4 }. 16

17 Identifying tail calls T[(lambda (args) body 1 body n )] = T [body n ] where the auxiliary function T is defined as follows: T [(let (defs) body 1 body n )] = T [body n ] T [(if e 1 e 2 e 3 )] = T [e 2 ] T [e 3 ] T [ m (e 1 e 2 e n )] when e 1 is not a primitive = { m } T [anything else] = 17

18 Tail call elimination in uncooperative environments

19 TCE in various environments When generating assembly language, it is easy to perform TCE, as the target language is sufficiently low-level to express the deallocation of the activation frame and the following jump. When targeting higher-level languages, like C or the JVM, this becomes difficult although recent VMs like.net s support tail calls. We explore several techniques that have been developed to perform TCE in such contexts. 19

20 Benchmark program To illustrate how the various techniques work, we will use a benchmark program in C that tests whether a number is even, using two mutually tail-recursive functions. When no technique is used to manually eliminate tail calls, it looks as follows. And unless the C compiler performs tail call elimination like gcc does with full optimisation it crashes with a stack overflow at run time. int even(int x) { return x == 0? 1 : odd(x - 1); } int odd(int x) { return x == 0? 0 : even(x - 1); } int main(int argc, char* argv[]) { printf("%d\n", even( )); } 20

21 Single function approach The single function approach consists in compiling the whole program to a single function of the target language. This makes it possible to compile tail calls to simple jumps within that function, and other calls to recursive calls to it. This technique is rarely applicable in practice, due to limitations in the size of functions of the target language. 21

22 Single function approach in C typedef enum { fun_even, fun_odd } fun_id; int wholeprog(fun_id fun, int x) { start: switch (fun) { case fun_even: if (x == 0) return 1; fun = fun_odd; x = x - 1; goto start; case fun_odd: if (x == 0) return 0; fun = fun_even; x = x - 1; goto start; } } int main(int argc, char* argv[]) { printf("%d\n", wholeprog(fun_even, )); } 22

23 Trampolines With trampolines, functions never perform tail calls directly. Rather, they return a special value to their caller, informing it that a tail call should be performed. The caller performs the call itself. For this scheme to work, it is necessary to check the return value of all functions, to see whether a tail call must be performed. The code which performs this check is called a trampoline. 23

24 Trampolines in C typedef void* (*fun_ptr)(int); struct { fun_ptr fun; int arg; } resume; void* even(int x) { if (x == 0) return (void*)1; resume.fun = odd; resume.arg = x - 1; return &resume; } void* odd(int x) { if (x == 0) return (void*)0; resume.fun = even; resume.arg = x - 1; return &resume; } int main(int argc, char* argv[]) { void* res = even( ); while (res == &resume) res = (resume.fun)(resume.arg); printf("%d\n",(int)res); } 24

25 Extended trampolines Extended trampolines trade some of the space savings of standard trampolines for speed. Instead of returning to the trampoline on every tail call, the number of successive tail calls is counted at run time, using a tail call counter (tcc) passed to every function. When that number reaches a predefined limit l, a non-local return is performed to transfer control to a trampoline waiting at the bottom of the chain, thereby reclaiming l activation frames in one go. 25

26 C s setjmp / longjmp Extended trampolines are more efficient when a non-local return is used to free dead stack frames. In C, non-local returns can be performed using the standard functions setjmp and longjmp, which can be seen as a form of goto that works across functions: setjmp(b) saves its calling environment in b, and returns 0, longjmp(b,v) restores the environment stored in b, and proceeds like if the call to setjmp had returned v instead of 0. In the following slides, we use _setjmp and _longjmp, which do not save and restore the signal mask and are therefore much more efficient. 26

27 Extended trampolines in C typedef int (*fun_ptr)(int, int); struct { fun_ptr fun; int arg; } resume; jmp_buf jmp_env; int even(int tcc, int x) { if (tcc > TC_LIMIT) { resume.fun = even; resume.arg = x; _longjmp(jmp_env, -1); } return (x == 0)? 1 : odd(tcc + 1, x - 1); } int odd(int tcc, int x) { /* similar to even */ } int main(int argc, char* argv[]) { int res = (_setjmp(jmp_env) == 0)? even(0, ) : (resume.fun)(0, resume.arg); printf("%d\n",res); } 27

28 Baker s technique Baker s technique consists in first transforming the whole program to continuation-passing style. One important property of CPS is that all calls are tail calls. Consequently, it is possible to periodically shrink the whole stack using a non-local return. 28

29 Baker s technique in C typedef void (*cont)(int); typedef void (*fun_ptr)(int, cont); int tcc = 0; struct { fun_ptr fun; int arg; cont k; } resume; jmp_buf jmp_env; void even_cps(int x, cont k) { if (++tcc > TC_LIMIT) { tcc = 0; resume.fun = even_cps; resume.arg = x; resume.k = k; _longjmp(jmp_env, -1); } if (x == 0) (*k)(1); else odd_cps(x - 1, k); } void odd_cps(int x, cont k) { /* similar to even_cps */ } int main(int argc, char* argv[]) { if (_setjmp(jmp_env) == 0) even_cps( , main_1); else (resume.fun)(resume.arg, resume.k); } void main_1(int val) { printf("%d\n", val); exit(0); } 29

30 Techniques summary None Single function Trampolines Extended trampolines Baker's non-tail call tail call normal return trampoline return non-local return 30

31 Benchmark 1 To get an idea of the relative performance of the techniques just presented, we first compiled all benchmarks without optimisation, using gcc 4.01 on a PowerPC G4. The version of the program that doesn t perform tail call elimination results in a stack overflow, and is therefore not included below. The normalised running times of the other versions are presented below. single function 1.0 trampolines 3.0 extended trampolines Baker s technique

32 Benchmark 2 As a second experiment, we compiled all programs with full optimisation. This enables the first version of the program to complete successfully, as gcc 4.01 performs at least some amount of tail call elimination. The normalised running times are presented below. initial version single function trampolines 23.4 extended trampolines Baker s technique

33 Summary Tail call elimination consists in compiling tail calls specially, so that the activation frame of the caller is freed before the called function is invoked. This technique reduces memory usage and makes it possible to write loops using recursion without overflowing the stack. Tail call elimination can be hard to implement efficiently when the target platform is uncooperative. 33

### Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Interpreters and virtual machines Michel Schinz 2007 03 23 Interpreters Interpreters Why interpreters? An interpreter is a program that executes another program, represented as some kind of data-structure.

### Lecture 18-19 Data Types and Types of a Language

Lecture 18-19 Data Types and Types of a Language April 29, 2014 Data Types and Types of a Language Data, Data Types and Types Type: Generalities Type Systems and Type Safety Type Equivalence, Coercion

### 15-150 Lecture 11: Tail Recursion; Continuations

15-150 Lecture 11: Tail Recursion; Continuations Lecture by Dan Licata February 21, 2011 In this lecture we will discuss space usage: analyzing the memory it takes your program to run tail calls and tail

### Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz 2007 03 16

Advanced compiler construction Michel Schinz 2007 03 16 General course information Teacher & assistant Course goals Teacher: Michel Schinz Michel.Schinz@epfl.ch Assistant: Iulian Dragos INR 321, 368 64

### Memory management in C: The heap and the stack

Memory management in C: The heap and the stack Leo Ferres Department of Computer Science Universidad de Concepción leo@inf.udec.cl October 7, 2010 1 Introduction When a program is loaded into memory, it

### Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

### Recursion in C. What does the following program compute? int f(int n, int v) { if (n == 0) return v; else return f(n - 1, v + n); }

Recursion in C What does the following program compute? int f(int n, int v) { if (n == 0) return v; else return f(n - 1, v + n); } int main() { return f(1000000, 0); } Answer: stack overflow 1-2 Loops

### 05 Case Study: C Programming Language

CS 2SC3 and SE 2S03 Fall 2009 05 Case Study: C Programming Language William M. Farmer Department of Computing and Software McMaster University 18 November 2009 The C Programming Language Developed by Dennis

### MIPS Calling Convention

MIPS Calling Convention This document summarizes the calling conventions that we expect you to use in ECE 314 for homework problems and assembly language programming projects. These are the rules for how

### COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation

### Exam in EDAA25 C Programming

Exam in EDAA25 C Programming October 30, 2014, 14-19 Inga hjälpmedel! Examinator: Jonas Skeppstedt Grading instructions In general: assess if a function or program works as intended while ignoring syntax

### Programming Languages Tail Recursion and Accumulators. Material adapted from Dan Grossman's PL class, U. Washington

Programming Languages Tail Recursion and Accumulators Material adapted from Dan Grossman's PL class, U. Washington Recursion Should now be comfortable with recursion: No harder than using a loop (Maybe?)

### GSM. Global System for Mobile Communications, 1992. Security in mobile phones. System used all over the world. Sikkerhed04, Aften Trusler

GSM Global System for Mobile Communications, 1992 Security in mobile phones System used all over the world 1 GSM: Threat Model What Cloning Eavesdropping Tracking Who Criminals Secret Services Why Break

### 2. Names, Scopes, and Bindings

2. Names, Scopes, and Bindings Binding, Lifetime, Static Scope, Encapsulation and Modules, Dynamic Scope Copyright 2010 by John S. Mallozzi Names Variables Bindings Binding time Language design issues

### Memory management. The memory manager. Explicit deallocation. Advanced Compiler Construction Michel Schinz

Memory management Memory management Advanced Compiler Construction Michel Schinz 2014 04 10 The memory of a computer is a finite resource. Typical programs use a lot of memory over their lifetime, but

### Q1. For the following grammar: S a S b c E E d f E a

Chapter 3 (3.1 3.3) Describing Syntax and Semantics Chapter 4 Lexical and Syntax Analysis Chapter 5 Names, Binding, Type Checking and Scopes Chapter 6 Data Types Chapter 7 Expressions and Assignment Statements

### C Primer. Fall Introduction C vs. Java... 1

CS 33 Intro Computer Systems Doeppner C Primer Fall 2016 Contents 1 Introduction 1 1.1 C vs. Java.......................................... 1 2 Functions 1 2.1 The main() Function....................................

### CSC230 Getting Starting in C. Tyler Bletsch

CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly

### Compiling Scala to LLVM

Compiling Scala to LLVM Geoff Reedy University of New Mexico Scala Days 2011 Motivation Why Scala on LLVM? Compiles to native code Fast startup Efficient implementations Leverage LLVM optimizations/analyses

### Computer Architecture and Assembly Language. Practical Session 4

Computer Architecture and Assembly Language Practical Session 4 Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _, \$, #, @,

### SYSTEMS PROGRAMMING C++ INTRODUCTION

Faculty of Computer Science / Institute of Systems Architecture / Operating Systems SYSTEMS PROGRAMMING C++ INTRODUCTION Alexander Warg WHY C++? C++ is the language that allows to express ideas from the

### The if-statement. Simple and compound statements. The if-statement comes in two forms: Simple statements:

1 2 Simple and compound s The if- Simple s: E.g.: expression; Various jumps : break, goto, continue, return. k = a * p + 3; printf("k = %d\n", k); 1 + 2; ; The if- comes in two forms: or E.g.: if (expression)

### Introduction. dnotify

Introduction In a multi-user, multi-process operating system, files are continually being created, modified and deleted, often by apparently unrelated processes. This means that any software that needs

### Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Common to: CSE 2 nd sem IT 2 nd sem Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart

### M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: IMPORTANT INSTRUCTIONS: 1. Question Paper in English and Hindi and Candidate can choose any one language. 2. In case of discrepancies in

### Introduction to C Programming S Y STEMS

Introduction to C Programming CS 40: INTRODUCTION TO U NIX A ND L I NUX O P E R AT ING S Y STEMS Objectives Introduce C programming, including what it is and what it contains, which includes: Command line

### Keywords Compared in Various Languages

Keywords Compared in Various Languages Visual Studio 2010 This topic lists common programming tasks that can be summarized with a language keyword. For more information about tasks that need code examples,

### CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 20: Stack Frames 7 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Where We Are Source code if (b == 0) a = b; Low-level IR code

### Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types In this lecture Computer Languages Assembly Language The compiler Operating system Data and program instructions Bits, Bytes and Data Types ASCII table Data Types

### Surface and Volumetric Data Rendering and Visualisation

Surface and Volumetric Data Rendering and Visualisation THE Qt TOOLKIT Department of Information Engineering Faculty of Engineering University of Brescia Via Branze, 38 25231 Brescia - ITALY 1 What is

### Variables. CS181: Programming Languages

Variables CS181: Programming Languages Topics: Static vs. dynamic typing Strong vs. weak typing Pointers vs. references Vladimir Vacic, Christos Koufogiannakis, University of California at Riverside 2

### 2 Imperative Programming Languages

2 Imperative Programming Languages We start our presentation with the translation of an imperative programming language. As an example, we consider a subset of the programming language C. Our target language

### Crash Course in Java

Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

### INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming

INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C

### Debugging Heap Corruption in Visual C++ Using Microsoft Debugging Tools for Windows

Using Microsoft Debugging Tools for Windows Version 10.0 David Dahlbacka Contents Heap Corruption... 2 Causes of Heap Corruption... 2 Debugging Heap Corruption... 2 Debugging Tools...3 Specific WinDbg

### Object Oriented Software Design II

Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

### Specific Simple Network Management Tools

Specific Simple Network Management Tools Jürgen Schönwälder University of Osnabrück Albrechtstr. 28 49069 Osnabrück, Germany Tel.: +49 541 969 2483 Email: Web:

### Local workspace of a subroutine: Recursion and recursive subroutines:

Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary private variables used in addition to available data registers. Recursion and recursive

### Mutual Exclusion using Monitors

Mutual Exclusion using Monitors Some programming languages, such as Concurrent Pascal, Modula-2 and Java provide mutual exclusion facilities called monitors. They are similar to modules in languages that

### Lecture 4. Announcements:

Announcements: Lecture 4 HW1 posted on Saturday morning. We gave a little over a week. We are going to discuss relevant material over the next two lectures. Lab1 posted. But if you start doing it, you

### Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

### Programming for MSc Part I

Herbert Martin Dietze University of Buckingham herbert@the-little-red-haired-girl.org July 24, 2001 Abstract The course introduces the C programming language and fundamental software development techniques.

### Memory Management in Java

CMSC 433 Programming Language Technologies and Paradigms Spring 2006 Memory Management Memory Management in Java Local variables live on the Allocated at method invocation time Deallocated when method

### Content. Introduction and History. File I/O. The File System. Shell Programming. Standard Unix Files and Configuration. Processes

Content Introduction and History File I/O The File System Shell Programming Standard Unix Files and Configuration Processes Programs are instruction sets stored on a permanent medium (e.g. harddisc). Processes

### Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.

Code Generation I Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.7 Stack Machines A simple evaluation model No variables

### IC221: Systems Programming 06-Week Written Exam [SOLUTIONS]

IC221: Systems Programming 06-Week Written Exam [SOLUTIONS] February 12, 2014 Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back

### Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 02 Lecture No. # 05 Run-time Environments-Part 3 and Local Optimizations

### Malloc'd objects, garbage collection, and memory leaks

Malloc'd objects, garbage collection, and memory leaks Some languages (e.g. Java) provides for "automagic" garbage collection in which storage for an object is magically reclaimed when all references to

### Efficient Compilation of Tail Calls and Continuations to JavaScript

Efficient Compilation of Tail Calls and Continuations to JavaScript Eric Thivierge Marc Feeley Université de Montréal feeley@iro.umontreal.ca Abstract This paper describes an approach for compiling Scheme

### Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

### Leak Check Version 2.1 for Linux TM

Leak Check Version 2.1 for Linux TM User s Guide Including Leak Analyzer For x86 Servers Document Number DLC20-L-021-1 Copyright 2003-2009 Dynamic Memory Solutions LLC www.dynamic-memory.com Notices Information

### Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

Channel Access Client Programming Andrew Johnson Computer Scientist, AES-SSG Channel Access The main programming interface for writing Channel Access clients is the library that comes with EPICS base Written

### C Compiler Targeting the Java Virtual Machine

C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the

OPERATING SYSTEMS IIIT-Hyderabad OVERVIEW Introduction What is an OS/Kernel? Bootstrap program Interrupts and exceptions Volatile and Non volatile storage!!! Process Management What is a process/system

### Recursion vs. Iteration Eliminating Recursion

Recursion vs. Iteration Eliminating Recursion continued CS 311 Data Structures and Algorithms Lecture Slides Monday, February 16, 2009 Glenn G. Chappell Department of Computer Science University of Alaska

### Implementing exceptions in the C programming language

1 Adomas Paltanavičius, Student of Vilnius Lyceum, Class 2B IMPLEMENTING EXCEPTIONS IN THE C PROGRAMMING LANGUAGE...1 INTRODUCTION...1 INTRODUCING EXCEPTIONS...1 MOTIVATION...2 LICENSE...2 SOURCE STRUCTURE...2

### Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)

### The C Programming Language course syllabus associate level

TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

### The programming language C. sws1 1

The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

### CORBA Programming with TAOX11. The C++11 CORBA Implementation

CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy

### C++ Keywords. If/else Selection Structure. Looping Control Structures. Switch Statements. Example Program

C++ Keywords There are many keywords in C++ that are not used in other languages. bool, const_cast, delete, dynamic_cast, const, enum, extern, register, sizeof, typedef, explicit, friend, inline, mutable,

### PROJECT 3 - MULTITHREADED WEB SPIDER Computer Systems Principles. October 28, 2010

PROJECT 3 - MULTITHREADED WEB SPIDER Computer Systems Principles Emery Berger Mark Corner October 28, 2010 1 Overview Goals of this assignment: understanding threads; understanding mutual exclusion; using

### Programming Languages

Programming Languages Memory Allocation & Garbage Collection CSCI.GA-2110-003 Fall 2011 Dynamic memory management For most languages, the amount of memory used by a program cannot be determined at compile

### High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

### Introduction. What is an Operating System?

Introduction What is an Operating System? 1 What is an Operating System? 2 Why is an Operating System Needed? 3 How Did They Develop? Historical Approach Affect of Architecture 4 Efficient Utilization

### Optimization Techniques in C. Team Emertxe

Optimization Techniques in C Team Emertxe Optimization Techniques Basic Concepts Programming Algorithm and Techniques Optimization Techniques Basic Concepts What is Optimization Methods Space and Time

### C for Java Programmers

C for Java Programmers CS 414 / CS 415 Niranjan Nagarajan Department of Computer Science Cornell University niranjan@cs.cornell.edu Original Slides: Alin Dobra Why use C instead of Java Intermediate-level

### Question Points Score 1 25 2 15 3 20 4 25 5 15 Total 100

Midterm #1 CMSC 412 Operating Systems Fall 2005 October 17, 2005 Guidelines This exam has 10 pages (including this one); make sure you have them all. Put your name on each page before starting the exam.

### Using Trace Replayer Debugger and Managing Traces in IDA

Using Trace Replayer Debugger and Managing Traces in IDA Copyright 2014 Hex-Rays SA Table of contents Introduction...2 Quick Overview...2 Following this tutorial...2 Supplied files...2 Replaying and managing

### Synchronization in Java

Synchronization in Java We often want threads to co-operate, typically in how they access shared data structures. Since thread execution is asynchronous, the details of how threads interact can be unpredictable.

### Operating Systems. Privileged Instructions

Operating Systems Operating systems manage processes and resources Processes are executing instances of programs may be the same or different programs process 1 code data process 2 code data process 3

### Linux Process Scheduling Policy

Lecture Overview Introduction to Linux process scheduling Policy versus algorithm Linux overall process scheduling objectives Timesharing Dynamic priority Favor I/O-bound process Linux scheduling algorithm

### Tutorial on C Language Programming

Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

### ICS 233 Computer Architecture & Assembly Language

ICS 233 Computer Architecture & Assembly Language Assignment 3 SOLUTION: Procedures in MIPS Assembly Language For the following problems, the table holds C code functions. Assume that the first function

### MIT Aurangabad FE Computer Engineering

MIT Aurangabad FE Computer Engineering Unit 1: Introduction to C 1. The symbol # is called a. Header file c. include b. Preprocessor d. semicolon 2. The size of integer number is limited to a. -32768 to

### 1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

Stack Overflows Mitchell Adair Outline Why? What? There once was a VM Virtual Memory Registers Stack stack1, stack2, stack3 Resources Why? Real problem Real money Real recognition Still prevalent Very

### CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development Dan Grossman Spring 2005 Lecture 25 Memory-Management Idioms Dan Grossman CSE303 Spring 2005, Lecture 25 1 No tools or rule today Review: Java and C

### Software Vulnerabilities

Software Vulnerabilities -- stack overflow Code based security Code based security discusses typical vulnerabilities made by programmers that can be exploited by miscreants Implementing safe software in

### CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17 System Calls for Processes Ref: Process: Chapter 5 of [HGS]. A program in execution. Several processes are executed concurrently by the

### Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include

### First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

### SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK (2110003) [F.Y.B.E.

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK Subject: Computer Programming and Utilization (2110003) [F.Y.B.E.: ALL BRANCHES] Unit 1

### C A short introduction

About these lectures C A short introduction Stefan Johansson Department of Computing Science Umeå University Objectives Give a short introduction to C and the C programming environment in Linux/Unix Go

### How I Learned to Stop Fuzzing and Find More Bugs

How I Learned to Stop Fuzzing and Find More Bugs Jacob West Fortify Software August 3-5, 2007 Las Vegas Agenda Introduction to fuzzing What is fuzzing? Challenges with fuzzing Introduction to static analysis

### Expert C Programming. Deep C Secrets. Peter van der Linden. SunSoft Press A Prentice Hall Title

Expert C Programming Deep C Secrets Peter van der Linden SunSoft Press A Prentice Hall Title Contents Preface Xiii Acknowledgments xv Introduction xix The \$20 Million Bug xx Converdi on xxi Some Light

### GENERIC and GIMPLE: A New Tree Representation for Entire Functions

GENERIC and GIMPLE: A New Tree Representation for Entire Functions Jason Merrill Red Hat, Inc. jason@redhat.com 1 Abstract The tree SSA project requires a tree representation of functions for the optimizers

### The current topic: Scheme. Announcements. Numeric operators. Review: car, cdr, and cons

The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction Next up: Numeric operators, REPL, quotes, functions, conditionals Types and values

### Defending Computer Networks Lecture 3: More On Vulnerabili3es. Stuart Staniford Adjunct Professor of Computer Science

Defending Computer Networks Lecture 3: More On Vulnerabili3es Stuart Staniford Adjunct Professor of Computer Science Enrollment Logis;cs Send request to cs- course- enroll@cornell.edu Cc me (sgs235@cornell.edu)

### ZDS II for ez80acclaim!: Calling C Functions from Assembly and Vice Versa AN

ZDS II for ez80acclaim!: Calling C Functions from Assembly and Vice Versa AN033301-0711 Abstract Discussion In certain situations, developers find that they must combine source code files written in Assembly

### Your first C program. Which one is best?

Your first C program #include void main(void) { printf( Hello, world!\n ); } #include void main(void) { printf( Hello, ); printf( world! ); printf( \n ); } Which one is best? #include

### CS193D Handout 04 Winter 2005/2006 January 11, 2006 A Crash Course in C++

CS193D Handout 04 Winter 2005/2006 January 11, 2006 A Crash Course in C++ Most people taking CS193D will already have some experience with C++. This handout is a quick refresher in case it s been a while.

### Data Structures and Algorithms C++ Implementation

BK TP.HCM Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering BK TP.HCM Data Structures and Algorithms C++ Implementation Huỳnh Tấn Đạt Email: htdat@cse.hcmut.edu.vn Home

### Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.828 Operating System Engineering: Fall 2005

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.828 Operating System Engineering: Fall 2005 Quiz II Solutions Average 84, median 83, standard deviation

### Recursive void Methods. Chapter 11. A recursive method is a method that includes a call to itself Recursion is based on the general problem.

Chapter 11 Recursion Recursive void Methods A recursive method is a method that includes a call to itself Recursion is based on the general problem solving technique of breaking down a task into subtasks

### Threads Scheduling on Linux Operating Systems

Threads Scheduling on Linux Operating Systems Igli Tafa 1, Stavri Thomollari 2, Julian Fejzaj 3 Polytechnic University of Tirana, Faculty of Information Technology 1,2 University of Tirana, Faculty of

### Java's garbage-collected heap

Sponsored by: This story appeared on JavaWorld at http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html Java's garbage-collected heap An introduction to the garbage-collected heap of the Java