UT Dallas CS 4337 - #Sebesta ch09 subprogram (65 pages)

Previewing pages 1, 2, 3, 4, 30, 31, 32, 33, 34, 62, 63, 64, 65 of 65 page document View the full content.
View Full Document

#Sebesta ch09 subprogram



Previewing pages 1, 2, 3, 4, 30, 31, 32, 33, 34, 62, 63, 64, 65 of actual document.

View the full content.
View Full Document
View Full Document

#Sebesta ch09 subprogram

29 views


Pages:
65
School:
University of Texas at Dallas
Course:
Cs 4337 - Organization of Programming Languages

Unformatted text preview:

Chapter 9 Subprograms Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly Overloaded Subprograms Generic Subprograms Design Issues for Functions User Defined Overloaded Operators Closures Coroutines Copyright 2012 Addison Wesley All rights reserved 1 2 Introduction Two fundamental abstraction facilities Process abstraction Emphasized from early days Discussed in this chapter Data abstraction Emphasized in the1980s Discussed at length in Chapter 11 Copyright 2012 Addison Wesley All rights reserved 1 3 Fundamentals of Subprograms Each subprogram has a single entry point The calling program is suspended during execution of the called subprogram Control always returns to the caller when the called subprogram s execution terminates Copyright 2012 Addison Wesley All rights reserved 1 4 Basic Definitions A subprogram definition describes the interface to and the actions of the subprogram abstraction In Python function definitions are executable in all other languages they are non executable In Ruby function definitions can appear either in or outside of class definitions If outside they are methods of Object They can be called without an object like a function In Lua all functions are anonymous A subprogram call is an explicit request that the subprogram be executed Copyright 2012 Addison Wesley All rights reserved 1 5 Basic Definitions A subprogram header is the first part of the definition including the name the kind of subprogram and the formal parameters The parameter profile aka signature of a subprogram is the number order and types of its parameters The protocol is a subprogram s parameter profile and if it is a function its return type Copyright 2012 Addison Wesley All rights reserved 1 6 Basic Definitions continued Function declarations in C and C are often called prototypes A subprogram declaration provides the protocol but not the body of the subprogram A formal parameter is a dummy variable listed in the subprogram header and used in the subprogram An actual parameter represents a value or address used in the subprogram call statement Copyright 2012 Addison Wesley All rights reserved 1 7 Actual Formal Parameter Correspondence Positional The binding of actual parameters to formal parameters is by position the first actual parameter is bound to the first formal parameter and so forth Safe and effective Keyword The name of the formal parameter to which an actual parameter is to be bound is specified with the actual parameter Advantage Parameters can appear in any order thereby avoiding parameter correspondence errors Disadvantage User must know the formal parameter s names Copyright 2012 Addison Wesley All rights reserved 1 8 Formal Parameter Default Values In certain languages e g C Python Ruby Ada PHP formal parameters can have default values if no actual parameter is passed In C default



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view #Sebesta ch09 subprogram and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view #Sebesta ch09 subprogram and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?