OpenVMS Pascal : Variable arguments passing

Post Reply

Topic author
garyrevell
Active Contributor
Posts: 38
Joined: Thu Nov 19, 2020 7:15 am
Reputation: 0
Location: Basingstoke, UK
Status: Offline
Contact:

OpenVMS Pascal : Variable arguments passing

Post by garyrevell » Mon Jan 17, 2022 4:54 pm

Hi,

I've looked through the VSI Pascal reference documentation but can't see any mention/examples of variable argument passing. Now it could be that I've missed it or that it's not allowed BUT writeln(...) for example allows the passing of various arguments so wondered if there was a way to do it for user code?

Any pointers/ideas would be great.

Thanks

Gary


willemgrooters
Valued Contributor
Posts: 73
Joined: Fri Jul 12, 2019 1:59 pm
Reputation: 0
Location: Netherlands
Status: Offline
Contact:

Re: OpenVMS Pascal : Variable arguments passing

Post by willemgrooters » Tue Jan 18, 2022 12:44 pm

Can you give a code example of what you like to achieve: variable number of arguments (and if so, how many), arguments that will be modified? (the latter is simple: specify the argument as 'var' :
Procedure (readonly, var to_be_modified)


jreagan
VSI Expert
Member
Posts: 9
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: OpenVMS Pascal : Variable arguments passing

Post by jreagan » Tue Jan 18, 2022 1:28 pm

Look at the LIST attribute in chapter 10, and ARGUMENT_LIST_LENGTH/ARGUMENT in chapter 8. It isn't completely flexible with accepting multiple types so you can't do what WRITELN does. Things like WRITELN are built directly into the compiler. They are statements, not routine calls.
Last edited by jreagan on Tue Jan 18, 2022 1:28 pm, edited 1 time in total.

User avatar

arne_v
Valued Contributor
Posts: 67
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: OpenVMS Pascal : Variable arguments passing

Post by arne_v » Wed Jan 19, 2022 10:14 am

Example similar to what is in the manual:

Code: Select all

program va(input,output);

procedure demo(v : [LIST] integer);

var
   i : integer;

begin
   for i := 1 to argument_list_length(v) do begin
      write(' ',argument(v,i):1);
   end;
   writeln;
end;

begin
   demo(1);
   demo(1, 2);
   demo(1, 2, 3);
end.
Added in 9 hours 57 minutes 20 seconds:
If you want to do C style programming:

Code: Select all

program va2(input,output);

type
   pstring = varying[255] of char;
   integer_ptr = ^integer;
   pstring_ptr = ^pstring;

procedure demo(v : [LIST] pointer);

var
   p : pointer;
   ip : integer_ptr;
   sp : pstring_ptr;
   iv : integer;
   sv : pstring;
   i : integer;


begin
   for i := 1 to argument_list_length(v) do begin
      p := argument(v,i);
      if odd(i) then begin
         ip := p;
         iv := ip^;
         write(' ',iv:1);
      end else begin
         sp := p;
         sv := sp^;
         write(' ',sv);
      end;
   end;
   writeln;
end;

var
   one, three, five : [VOLATILE] integer;
   two, four : [VOLATILE] varying[255] of char;

begin
   one := 1;
   two := 'BB';
   three := 3;
   four := 'DDDD';
   five := 5;
   demo(address(one));
   demo(address(one), address(two));
   demo(address(one), address(two), address(three));
   demo(address(one), address(two), address(three), address(four));
   demo(address(one), address(two), address(three), address(four), address(five));
end.
Added in 54 minutes 27 seconds:
Or a little nicer:

Code: Select all

program va3(input,output);

type
   pstring = varying[255] of char;
   integer_ptr = ^integer;
   pstring_ptr = ^pstring;
   wrapped_typ = (integer_typ, pstring_typ);
   wrapper = record
                typ : wrapped_typ;
                adr : pointer;
             end;

function iwrap(p : pointer) : wrapper;

var
   res : wrapper;

begin
   res.typ := integer_typ;
   res.adr := p;
   iwrap := res;
end;

function swrap(p : pointer) : wrapper;

var
   res : wrapper;

begin
   res.typ := pstring_typ;
   res.adr := p;
   swrap := res;
end;

function iunwrap(w : wrapper) : integer;

var
   p : integer_ptr;

begin
   p := w.adr;
   iunwrap := p^;
end;

function sunwrap(w : wrapper) : pstring;

var
   p : pstring_ptr;

begin
   p := w.adr;
   sunwrap := p^;
end;

procedure demo(v : [LIST] wrapper);

var
   w : wrapper;
   i : integer;

begin
   for i := 1 to argument_list_length(v) do begin
      w := argument(v,i);
      case w.typ of
         integer_typ:
            begin
               write(' ',iunwrap(w):1);
            end;
         pstring_typ:
            begin
               write(' ',sunwrap(w));
            end;
      end;
   end;
   writeln;
end;

var
   one, three, five : [VOLATILE] integer;
   two, four : [VOLATILE] varying[255] of char;

begin
   one := 1;
   two := 'BB';
   three := 3;
   four := 'DDDD';
   five := 5;
   demo(iwrap(address(one)));
   demo(iwrap(address(one)), swrap(address(two)));
   demo(iwrap(address(one)), swrap(address(two)), iwrap(address(three)));
   demo(iwrap(address(one)), swrap(address(two)), iwrap(address(three)), swrap(address(four)));
   demo(iwrap(address(one)), swrap(address(two)), iwrap(address(three)), swrap(address(four)), iwrap(address(five)));
end.
Arne
arne@vajhoej.dk
VMS user since 1986


Topic author
garyrevell
Active Contributor
Posts: 38
Joined: Thu Nov 19, 2020 7:15 am
Reputation: 0
Location: Basingstoke, UK
Status: Offline
Contact:

Re: OpenVMS Pascal : Variable arguments passing

Post by garyrevell » Mon Jan 24, 2022 10:00 am

Thanks everyone, and especially Arne for the example program

Best regards

Gary

Post Reply