208 Chapter Eight
argument(s) type(s) and return type must match for the function to
match the call.
The third call to function shiftrshows an example of a call where the
input argument matches the s_inttype function, but the return type of
the function does not match the target signal. With the functions cur-
rently described in package p_shift, no function matches exactly, and
therefore the compilation of the third line produces an error.
To make the third call legal, all that is needed is to define a function
that matches the types of the third call. An example of the function decla-
ration is shown in the following code line. The function body for this
function is left as an exercise for the reader:
FUNCTION shiftr( a : s_int) return s_array;
OVERLOADING SUBPROGRAM ARGUMENT TYPES To overload
argument types, the base type of the subprogram parameters or return
value must differ. For example, base types do not differ when two subtypes
are of the same type. Two functions that try to overload these subtypes pro-
duce a compile error. Following is an example:
PACKAGE type_error IS
SUBTYPE log4 IS BIT_VECTOR( 0 TO 3);
SUBTYPE log8 IS BIT_VECTOR( 0 TO 7);
-- this function is Ok
FUNCTION not( a : log4) return integer;
-- this function declaration will cause an
-- error
FUNCTION not( a : log8) return integer;
END type_error;
This package declares two subtypes log4and log8of the uncon-
strained BIT_VECTORtype. Two functions named notare then declared
using these subtypes. The first function declaration is legal, but the second
function declaration causes an error. The error is that two functions have
been declared for the same base type. The two types log4and log8are
not distinct, because they both belong to the same base type.
All of the examples shown so far have been overloading of functions.
Overloading of procedures works in the same manner.
SUBPROGRAM PARAMETER OVERLOADING Two or more sub-
programs with the same name can have a different number of parameters.