[fpc-pascal] More syntax questions (part 3)

Adriaan van Os adriaan at adriaan.biz
Sun Dec 17 09:09:46 CET 2023


Michael Van Canneyt via fpc-pascal wrote:
>> 28.  The documentation for macpas "UNIV" is missing ?
> 
> I have no idea what this is ?

UNIV is macpas specific (as mentioned in Appendix D.6 of the Programmer's Manual)

With UNIV,

	... ":" [ "ARRAY" "OF" ] type-identifier ...

  in the syntax diagrams, becomes

	... ":" [ "ARRAY" "OF" | UNIV ] type-identifier ...

The modifier UNIV indicates that the actual parameter can be of any type that has the same 
byte-size as the formal parameter.

Example:

	procedure HDispose( var theHandle: univ Handle); .....

which saves a value-type-cast when calling HDispose with handles that are not (precisely) of type 
Handle.

Another use of UNIV is type-compatibility of procedural parameters. For example with

  function BinaryFind
         (     theValuePtr             : univ UnivPtr;
               theFirstIndex           : Int32;
               theLastIndex           : Int32;
      function SmallerThan
         (     theIndex                : Int32;
               theValuePtr             : univ UnivPtr): boolean;
      function EqualTo
         (     theIndex                : Int32;
               theValuePtr             : univ UnivPtr): boolean;
           var theFoundIndex           : Int32): boolean;

we can call BinaryFind as follows

       theFoundFlag := BinaryFind
         ( @theCmdID, 1, kCmdCount, CmdIDSmallerThan, CmdIDEqualTo,

where

  function CmdIDSmallerThan
         (     theIndex                : Int32;
               theValuePtr             : CmdIDPtr): boolean; .....

and

function CmdIDEqualTo
         (     theIndex                : Int32;
               theValuePtr             : CmdIDPtr): boolean; ...

because CmdIDPtr is through UNIV type-compatible with

	theValuePtr : univ UnivPtr

Regards,

Adriaan van Os



More information about the fpc-pascal mailing list