9-Subprograms - 9. Subprograms 9.2 Fundamentals of...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
ICS 313 - Fundamentals of Programming Languages 1 9. Subprograms 9.2 Fundamentals of Subprograms ± General characteristics of subprograms ` A subprogram has a single entry point ` The caller is suspended during execution of the called subprogram ` Control always returns to the caller when the called subprogram’s execution terminates ± Basic definitions ` A subprogram definition is a description of the actions of the subprogram abstraction ` A subprogram call is an explicit request that the subprogram be executed ` A subprogram header is the first line of the definition, including the name, the kind of subprogram, and the formal parameters ` The parameter profile of a subprogram is the number, order, and types of its parameters ` The protocol of a subprogram is its parameter profile plus, if it is a function, its return type ` A subprogram declaration provides the protocol, but not the body, of the subprogram
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ICS 313 - Fundamentals of Programming Languages 2 9.2 Fundamentals of Subprograms (continued) ± 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 ± Actual/Formal Parameter Correspondence ` Positional ` Keyword e.g. SORT(LIST => A, LENGTH => N); ` Advantage: order is irrelevant ` Disadvantage: user must know the formal parameter’s names ± Default Values: ` e.g. procedure SORT(LIST : LIST_TYPE; LENGTH : INTEGER := 100); ... SORT(LIST => A); ± Procedures provide user-defined statements ± Functions provide user-defined operators 9.3 Design Issues for Subprograms ± What parameter passing methods are provided? ± Are parameter types checked? ± Are local variables static or dynamic? ± What is the referencing environment of a passed subprogram? ± Are parameter types in passed subprograms checked? ± Can subprogram definitions be nested? ± Can subprograms be overloaded? ± Are subprograms allowed to be generic? ± Is separate or independent compilation supported?
Background image of page 2
ICS 313 - Fundamentals of Programming Languages 3 9.4 Local referencing environments ± If local variables are stack-dynamic: ` Advantages ¾ Support for recursion ¾ Storage for locals is shared among some subprograms ` Disadvantages ¾ Allocation/deallocation time ¾ Indirect addressing ¾ Subprograms cannot be history sensitive ± Static locals are the opposite ± Language Examples ` FORTRAN 77 and 90 - most are static, but the implementor can choose either (User can force static with SAVE ) ` C - both (variables declared to be static are) (default is stack dynamic) ` Pascal, Java, and Ada - dynamic only 9.5 Parameter Passing Methods ± We discuss these at several different levels ` Semantic Models: in mode, out mode, inout mode ` Conceptual Models of Transfer ¾ Physically move a value ¾ Move an access path
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ICS 313 - Fundamentals of Programming Languages 4 9.5 Parameter Passing Methods (continued) ± Implementation Models ± Pass-by-value
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2010 for the course ICS ics103 taught by Professor Alvi during the Spring '07 term at King Fahd University of Petroleum & Minerals.

Page1 / 17

9-Subprograms - 9. Subprograms 9.2 Fundamentals of...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online