[comp.os.vms] Pascal and external routines

CARTER@MITBATES.BITNET (Tony Carter - MIT Bates Linac) (11/11/87)

>Regarding use of assorted system-defined status codes in Vax Pascal,
>doesn't the statement
>
>[INHERIT ('SYS$LIBRARY:STARLET')]
>
>at the top of the program, automatically include for you most, if not
>all, the system-defined status-code values, labels, etc. ?  I found this
>in the Pascal Reference Manual and/or User's Guide (can never quite keep
>the two straight), and it seems to work fine for most everything, EXCEPT:

Yes, it does. But you can also define you OWN error messages for use within
a program. These are obviously not going to be in any of the VMS-supplied
environment files.

>Part of the problem would be solved if someone can tell me how to declare
>a PROCEDURE or FUNCTION so as to allow "optional" parameters - i.e., so
>that you can omit a parameter when actually calling the routine.  I know
>it's possible because the system-service routines defined in STARLET.PEN
>allow you to omit parameters, but I haven't been able to get this to
>work in my own declarations, particularly for LIB$ routines.  Any informa-
>tion would be greatly appreciated; I feel like it shouldn't take much to
>clarify this for me - I feel that I'm just misunderstanding the effects
>of an "attribute" or two somewhere.

It's difficult to give a "course" in this over the net, but maybe an example
would be helpful. This program uses LIB$GETJPI and defines it so that optional
parameters are really optional:

---------------------------------cut here---------------------------------------
[inherit('sys$library:starlet')] program getuser(output);

type
  $word         = [word] -32768..32767;

var
  stat          : unsigned;
  username      : varying[80] of char;

[asynchronous,external] function lib$getjpi
        (%ref   itemcode : integer;
         var    processid : unsigned := %immed 0;
         %descr processname : varying[$u0] of char := %immed 0;
         var    outvalue : [unsafe] integer := %immed 0;
         %descr outstring : varying[$u1] of char := %immed 0;
         var    outlen : $word := %immed 0):unsigned;extern;

begin
  { No parameter between commas means use the default. }
  stat          := lib$getjpi(jpi$_username,,,,username);
  writeln(username);
  { Or use formal parameter name to indicate use. }
  stat          := lib$getjpi(itemcode:=jpi$_username,outstring:=username);
  writeln(username);
end.(*getuser*)
---------------------------------cut here---------------------------------------

The ":= %IMMED 0"'s tell Pascal what the default value for each parameter
is and how to pass it. This is how the system services and library routines
expect to be passed a "null" parameter ( a zero on the stack). The best
place to learn about these things is in the "Procedures and Functions"
section of the reference manual.


Tony Carter          CARTER@MITBATES       (Bitnet)
MIT Bates Linac      CARTER@MITLNS.MIT.EDU (Arpanet)
Middleton, MA