Copyright © 1996, 1997 Lucent Technologies Inc. All rights reserved.

9.11 return statement

The return statement,


return expressionopt ;
returns control to the caller of a function. If the function returns a value (that is, if its definition and declaration mention a return type), the expression must be given and it must have the same type that the function returns. If the function returns no value, the expression must generally be omitted. However, if a function returns no value, and its last action before returning is to call another function with no value, then it may use a special form of return that names the function being called. For example,
	f, g: fn(a: int);
	f(a: int) {
		. . .
		return g(a+1);
	}
is permitted. Its effect is the same as
	f(a: int) {
		. . .
		g(a+1);
		return;
	}
This ad hoc syntax offers the compiler a cheap opportunity to recognize tail-recursion.

Running off the end of a function is equivalent to return with no expression.

05/Jun/97