【正文】
** end of generic_sort 942 Generic Subprograms ? Example use: float flt_list[100]。 ... generic_sort(flt_list, 100)。 // Implicit instantiation 943 Separate amp。 Independent Compilation ? Def: Independent pilation is pilation of some of the units of a program separately from the rest of the program, without the benefit of interface information. 最重要的一個特征:單元接口之間不進行類型一致性檢測。 ? Def: Separate pilation is pilation of some of the units of a program separately from the rest of the program, using interface information to check the correctness of the interface between the two parts. 944 Separate amp。 Independent Compilation ? Language Examples: – FORTRAN II to FORTRAN 77 independent – FORTRAN 90, Ada, C++, Java separate – Pascal allows neither 945 ?Design Issues for Functions 1. Are side effects allowed?副作用 a. Twoway parameters (Ada does not allow) b. Nonlocal reference (all allow) 2. What types of return values are allowed? 946 Design Issues for Functions ? Language Examples (for possible return types): 1. FORTRAN, Pascal only simple types 2. C any type except functions and arrays 3. Ada any type (but subprograms are not types) 4. C++ and Java like C, but also allow classes to be returned 947 Accessing Nonlocal Environments ? Def: The nonlocal variables of a subprogram are those that are visible but not declared in the subprogram ? Def: Global variables are those that may be visible in all of the subprograms of a program 948 Accessing Nonlocal Environments ? Methods: 1. FORTRAN COMMON blocks – The only way in pre90 FORTRANs to access nonlocal variables – Can be used to share data or share storage 2. Static scoping discussed in Chapter 949 Accessing Nonlocal Environments ? Methods (continued): 3. External declarations C – Subprograms are not nested – Globals are created by external declarations (they are simply defined outside any function) – Access is by either implicit or explicit declaration – Declarations (not definitions) give types to externally defined variables (and say they are defined elsewhere) 950 Accessing Nonlocal Environments ? Methods (continued): 4. External modules Ada – More about these later (Chapter 11) 5. Dynamic Scope discussed in Chapter 5 951 UserDefined Overloaded Operators ? Nearly all programming languages have overloaded operators ? Users can further overload operators in C++ and Ada (Not carried over into Java) ? Are userdefined overloaded operators good or bad? More overloaded operators can impact the readability. 952 Coroutines 協(xié)同程序 ? A coroutine is a subprogram that has multiple entries and controls them itself, Also called symmetric對稱 control ? A coroutine call is named a resume再繼續(xù) ? The first resume of a coroutine is to its beginning, but subsequent calls enter at the point just after the last executed statement in the coroutine 953 Coroutines ? Typically, coroutines repeatedly resume each other, possibly forever ? Coroutines provide quasiconcurrent execution準(zhǔn)并發(fā)執(zhí)行 of program units (the coroutines) ? Their execution is interleaved交叉存取 , but not overlapped 954 Coroutines 955 Coroutines 956 Coroutines 957 Homework: 8 and 10