Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In.

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look 1 Xiang Lian The University of Texas – Pan American Edinburg,
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
AU/MITM/1.6 By Mohammed A. Saleh 1. Arguments passed by reference  Until now, in all the functions we have seen, the arguments passed to the functions.
1 Chapter Three Using Methods. 2 Objectives Learn how to write methods with no arguments and no return value Learn about implementation hiding and how.
Computer Programming 1 More on functions. Computer Programming 2 Objectives Function overloading Scope rules and namespace Inline Templates Pass by value.
2. Textual user interface NQC (Not quite C)  C-like programs translated into CRX-bytecode  Composed of: 1.Global variables 2.Task blocks 3.Inline functions.
Copyright 2006 by Pearson Education 1 reading: 4.1 Cumulative sum.
LEGO Mindstorms RIS 2.0 Programming: NQC Code B.A. Juliano and R.S. Renner September 2004 California State University, Chico Intelligent Systems Laboratory.
Using Variables Variables form a very important aspect of every programming language. Variables are memory locations in which we can store a value. We.
Tasks An NQC program consists of at most 10 tasks. Each task has a name. One task must have the name main, and this task will be executed. The other tasks.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Functions Modules in C++ are called functions and classes
Repeating Blocks of Code (updated 9/20/05 7:35pm) Reference NQC Tutorial pp 9-12.
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
CSCI 130 Chapter 2. Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition Comments.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
C++ function call by value The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter.
Chapter 6: User-Defined Functions
1 Web Based Programming Section 8 James King 12 August 2003.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
CSE 8A Lecture 8 Reading for next class: PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
Learners Support Publications Functions in C++
Chapters 1-5 Review C++ Class. Chapter 1 – the big picture Objects Class Inheritance Reusability Polymorphism and Overloading.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
1 Methods Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
NQC Brief Introduction – Part 2 David Schilling. NQC – Where to put code? Programs Tasks Functions Subroutines.
Chapter 6 Methods Chapter 6 - Methods.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
ROBOTC for IFI Timothy Friez Class #4 2/5/08. Agenda for Tonight Timers Functions Your Questions.
Review. Problem 1 What is the output of the following piece of code void increment(int x) { x++; } int main() { int y = 10; increment(y); cout
Programming Languages -2 C++ Lecture 3 Method Passing Function Recursion Function Overloading Global and Local variables.
Functions Dilshad M. Shahid New York
Objectives: How to define and call functions. Function declarations and how they differ from function definitions. How arguments are passed to functions.
Robotics Grant Agreement No LLP UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning in Mechatronics Technology.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
LECTURE 3 PASS BY REFERENCE. METHODS OF PASSING There are 3 primary methods of passing arguments to functions:  pass by value,  pass by reference, 
Introduction to Programming
Chapter 6: User-Defined Functions I
CSE 220 – C Programming Pointers.
Chapter 10: Void Functions
Functions and an Introduction to Recursion
INC 161 , CPE 100 Computer Programming
C Passing arrays to a Function
6.12 Default Arguments.
Variables and Their scope
Object-Oriented Programming Using C++ Second Edition
Return by Reference CSCE 121 J. Michael Moore.
Reference Parameters.
Simulating Reference Parameters in C
Functions and an Introduction to Recursion
A function is a group of statements that exist within a program for the purpose of performing a specific task. We can use functions to divide and conquer.
Subprograms Parameters.
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
Preprocessor Directives
NQC Program Structure 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions.
Compile and run c files.
Functions Chapter No. 5.
Presentation transcript:

Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In a sense, they are like #define, but they copy a block of code. There is no limit on the number of inline functions you can define.

void turn_around() { OnRev(OUT_C); Wait(340); OnFwd(OUT_A+OUT_C); } The name of the function is turn_around void indicates that it is an inlife function. task main() { OnFwd(OUT_A+OUT_C); Wait(100); turn_around(); Wait(200); turn_around(); Wait(100); turn_around(); Off(OUT_A+OUT_C); } The compiler will copy the code above each time the call to the inline function appears in a task.

void turn_around(int turntime) { OnRev(OUT_C); Wait(turntime); OnFwd(OUT_A+OUT_C); } An inline function can pass a value to the block of code. Instead of () use (int variable). This will define turntime within the function and allow you to pass different values to the function. task main() { OnFwd(OUT_A+OUT_C); Wait(100); turn_around(200); Wait(200); turn_around(50); Wait(100); turn_around(300); Off(OUT_A+OUT_C); }