Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

GENERIC attribute

The generic name must be explicitly declared with the GENERIC attribute.

Read syntax diagramSkip visual syntax diagram>>-generic-name--GENERIC--(--| references |--------------------->
 
>--+-------------------------+--)--;--| generic-descriptor: |--->
   '-,--entry-ref--OTHERWISE-'
 
>--data-attributes--+-----------+--+--------------------+------->
                    +-ALIGNED---+  +-ASSIGNABLE---------+
                    '-UNALIGNED-'  |               (1)  |
                                   '-NONASSIGNABLE------'
 
>--+-------------------+--+---------+--+--------------+--------->
   +-CONNECTED---------+  +-HEXADEC-+  +-BIGENDIAN----+
   |              (1)  |  '-IEEE----'  '-LITTLEENDIAN-'
   '-NONCONNECTED------'
 
>--+----------+------------------------------------------------><
   '-OPTIONAL-'
 
references
 
   .-,--------------------------------------------------.
   |                   .-,--------------------------.   |
   V                   V                            |   |
|----entry-ref--WHEN-(---+------------------------+-+-)-+-------|
                         +-| generic-descriptor |-+
                         '-*----------------------'
 

Notes:
  1. If specified, this keyword is ignored.

Abbreviation: OTHER for OTHERWISE

For the general declaration syntax, see DECLARE statement.

entry-ref
Must not be subscripted or defined. The same entry reference can appear more than once within a single GENERIC declaration with different lists of descriptors.
generic-descriptor
Corresponds to a single argument. It specifies an attribute that the corresponding argument must have so that the associated entry reference can be selected for replacement.

Structures or unions cannot be specified.

Where a descriptor is not required, its absence must be indicated by an asterisk.

The descriptor that represents the absence of all arguments in the invoking statement is expressed by omitting the generic descriptor in the WHEN clause of the entry. It has the form:

  generic (... entry1 when( ) ...)
data-attributes
Listed in Data types and attributes.
ALIGNED and UNALIGNED
Discussed in ALIGNED and UNALIGNED attributes.
ASSIGNABLE and NONASSIGNABLE
Discussed in ASSIGNABLE and NONASSIGNABLE attributes.
CONNECTED and NONCONNECTED
Discussed in CONNECTED and NONCONNECTED attributes.
HEXADEC and IEEE
Discussed in HEXADEC and IEEE attributes.
BIGENDIAN and LITTLEENDIAN
Discussed in BIGENDIAN and LITTLEENDIAN attributes.
OPTIONAL
Discussed in OPTIONAL attribute.

When an invocation of a generic name is encountered, the number of arguments specified in the invocation and their attributes are compared with descriptor list of each entry in the set. The first entry reference for which the descriptor list matches the arguments both in number and attributes replaces the generic name.

In the following example, an entry reference that has exactly two descriptors with the attributes DECIMAL or FLOAT, and BINARY or FIXED is searched for.

  declare Calc generic (
               Fxdcal when (fixed,fixed),
               Flocal when (float,float),
               Mixed  when (float,fixed),
               Error otherwise);
  Dcl     X decimal float (6),
          Y binary fixed (15,0);

 
          Z = X+Calc(X,Y);

If an entry with the exact number of descriptors with the exact attributes is not found, the entry with the OTHERWISE clause is selected if present. In the previous example, Mixed is selected as the replacement.

In a similar manner, an entry can be selected based on the dimensionality of the arguments.

  dcl  D generic (D1 when ((*))),
                  D2 when((*,*))),
       A(2),
       B(3,5);
  call D(A);      /* D1 selected because A has one dimension  */
  call D(B);      /* D2 selected because B has two dimensions */

If all of the descriptors are omitted or consist of an asterisk, the first entry reference with the correct number of descriptors is selected.

An entry expression used as an argument in a reference to a generic value matches only a descriptor of type ENTRY. If there is no such description, the program is in error.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)