HP 3000 Manuals

HP-UX Extensions [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

HP-UX Extensions 

HP-UX extensions are available only to programs that are compiled by the
HP Pascal compiler running on the HP-UX operating system.  The programs
themselves must also run on the HP-UX operating system.  The HP-UX
extensions are:

   *   Access to special global variables through the EXTERNAL directive.

   *   The predefined function get_alignment, which returns the alignment
       requirement of a given type or variable.

   *   The predefined function statement_number, which returns the
       statement number of the statement that calls it.

Accessing Special Global Variables 

The global variable errno is special in that a program can access it
through the EXTERNAL directive.

Example 

     $EXTERNAL$
     PROGRAM ErrorNo_Example;

     VAR
        ErrorNumber $ALIAS 'errno'$ : INTEGER;

     FUNCTION Pas_Errno : integer;
     BEGIN
        Pas_Errno := ErrorNumber;
     END;

     BEGIN
     END.

When another compilation unit is linked with the preceding program, it
can access the function Pas_Errno, which returns the value of the global
variable errno.

Fnum Function 

The predefined function fnum returns the HP-UX file number of the
physical file currently associated with a given logical file.  You[REV
BEG] can use this file number in system calls.[REV END]

Syntax 

     fnum (filename)

Parameter 

filename      The name of the logical file.  This parameter is required,
              even if the logical file is the standard file input or
              output.  The logical file must be associated with a
              physical file.

Example 

     program xref(output);
     const SEEK_SET=0;       { Set file pointer to "offset" }
           SEEK_CUR=1;       { Set file pointer to current plus "offset" }
           SEEK_END=2;       { Set file pointer to EOF plus "offset" }

     var s_file : text;
         max    : integer;
         f      : integer;

     function lseek(fildes:integer; offset:integer; whence:integer): integer;
        external;

     begin
     reset(s_file,'foo');
     f:=fnum(s_file);
     max:=lseek(f,0,seek_end);
     writeln('file#:',f:1,', max bytes=',max:1);
     end.

Output:

     file#:3, max bytes=487

Get_alignment Function 

The predefined function get_alignment returns the alignment requirement
of a given type or variable.

Syntax 

get_alignment ({variable})
               {type    }
Parameters 

variable      Any variable.  The function get_alignment returns its
              alignment requirement.

type          Any type identifier (the name of any type).  The function
              get_alignment returns its alignment requirement.

Example 

     PROGRAM prog;

     TYPE
        Rec = $ALIGNMENT 8$
              RECORD
                 f1 : integer;
                 f2 : shortint;
                 f3 : real;
              END;

        integer_ = $ALIGNMENT 2$ integer;

     VAR
        ptr : ^integer_;

     BEGIN
        i := get_alignment(rec);

        IF get_alignment(ptr^) <> 2 THEN
           .
           .
           .
     END.

Statement_number Function 

The predefined function statement_number returns the statement number of
the statement that calls it, as shown on the compiled listing.  It is a
useful debugging aid, especially when used with the predefined procedure
assert.

Syntax 

     statement_number

Example 

     PROGRAM prog (output);

     VAR
        i : integer;

     BEGIN
        i := statement_number;
        writeln('Current Statement Number is ', i);
        assert(a > b, statement_number);
     END.



MPE/iX 5.0 Documentation