[Info-vax] Redimensioning formal parameter arrays in OpenVMS BASIC
T. Kurt Bond
tkurtbond at gmail.com
Sat Feb 5 15:56:25 EST 2022
On Thursday, May 8, 2003 at 4:11:28 PM UTC-4, T. Kurt Bond wrote:
> The BASIC for OpenVMS Reference Manual says, in the fifth item of the
> Remarks section:
> The executable DIM statement cannot be used to dimension virtual arrays,
> arrays received as formal parameters, or arrays declared in COMMON, MAP,
> or nonexecutable DIM statements.
> http://h71000.www7.hp.com/doc/73final/cobol/bas_ref_013.htm#noisn
> The "no formal parameters" rule is inconvienent. It means that you
> can't pass an array to a function, redimension it, fill it with values,
> and then use LBOUND and UBOUND in the caller to find out its new size.
> Presumably it is illegal because there is no way at compile time to
> know if the function will be called with a dynamic array created with
> the executable DIM statement or a static array created with a
> non-executable DIM statement.
> However, the programmer *can* know, so it ought to be safe to
> redimension the array directly when the programmer knows it was
> created by an executable DIM statement.
> Using Alpha BASIC V1.4-000 under OpenVMS V7.2 and looking at the
> listing of some code with some executable dimension statements
> compiled with /LIST/MACHINE revealed the existance of DBASIC$RT_DIM
> and after a little experimentation lead to a program that used
> DBASIC$RT_DIM directly to redimension dynamically dimensioned arrays
> in functions[.]
> (Interestingly, a slightly different approach was necessary using VAX
> BASIC V3.5 under VMS V5.5-2: using BY VALUE in function
> definition statements is not allowed by this version of VAX BASIC,
> and BAS$RT_DIM had to be used instead of DBASIC$RT_DIM, of course.)
> --
> T. Kurt Bond, t... at tkb.mpl.com
I needed this again for a program I was writing on a VAX. (The VAX is running VMS V5.5-2; It's like I am in 1992 all over again!)
Anyway, I ended up figuring out how to pass the lower bound (call BAS$RT_DIM_BOUNDS instead) and how to use the same redim procedure with different types, plus simplified things a little. Here's my new version:
program vax_redim_best
option type = explicit, constant type = integer, &
size = integer long, size = real double
record rec
string s = 13
long i
end record rec
! Don't declare the parameters, and everything works, even passing
! different types.
external sub redim
declare long stat, i
i = 1
dim rec rec(1 to i)
print "lbound (rec) at start: "; lbound (rec)
print "ubound (rec) at start: "; ubound (rec)
call redim (rec(), 3, 10)
print "lbound (rec) after redim: "; lbound (rec)
print "ubound (rec) after redim: "; ubound (rec)
dim string s(1 to i)
print "lbound (s) at start: "; lbound (s)
print "ubound (s) at start: "; ubound (s)
call redim (s(), 3, 10)
print "lbound (s) after redim: "; lbound (s)
print "ubound (s) after redim: "; ubound (s)
dim long l(1 to i)
print "lbound (l) at start: "; lbound (l)
print "ubound (l) at start: "; ubound (l)
call redim (l(), 3, 10)
print "lbound (l) after redim: "; lbound (l)
print "ubound (l) after redim: "; ubound (l)
end program ! vax_redim_best
function long redim (long s, long low, long high)
option type = explicit, constant type = integer, &
size = integer long, size = real double
external long function bas$rt_dim_bounds (long by value, long by value, long by value)
declare long r
r = bas$rt_dim_bounds (loc (s), low, high)
end function r ! redim
More information about the Info-vax
mailing list