Default values of formal arguments can be given in a function specification as part of the specification's interface. The syntax is the same as that of C++. See section 5.4.6 Function Declarations for the syntax.
For example, consider the following function specification.
// @(#)$Id: interest.lh,v 1.4 1997/06/03 20:30:08 leavens Exp $ extern float interest(float x, float rate = 0.05) throw(); //@ behavior { //@ requires 0.0 <= rate /\ rate <= 1.0; //@ ensures result = x * rate; //@ }
The function interest
takes two float values denoted by
rate
and x
respectively, and computes interest based
on rate
. The default value of rate
is specified to be
0.05
; that is, if no value is supplied for rate
on function
invocation, 0.05
is used by default.
Go to the first, previous, next, last section, table of contents.