[Info-vax] VAX BASIC global variables.
E Thump
ethump at gmail.com
Fri Oct 15 12:09:40 EDT 2021
On Friday, October 15, 2021 at 4:44:49 PM UTC+1, Jeffrey H. Coffield wrote:
> On 10/15/2021 02:42 AM, E Thump wrote:
>
> >
> > Here's what I've done now:
> >
> > External SUB adder (integer,integer)
> > External INTEGER a,b
> >
> > a=100
> > b=200
> >
> > print "a+b before sub: ",a+b
> > call adder (10,20)
> > print "a+b after sub: ",a+b
> >
> > end program
> >
> > sub adder (integer c,integer d)
> > a=400
> > b=1000
> > print "a+b in sub: ",a+b
> > print "c+d in sub: ",c+d
> > end sub
> >
> > compiles clean but throws this when linking :
> >
> > %LINK-W-NUDFSYMS, 2 undefined symbols:
> > %LINK-I-UDFSYM, A
> > %LINK-I-UDFSYM, B
> > %LINK-W-USEUNDEF, undefined symbol A referenced
> > in psect $CODE offset %X00000021
> > in module TEST$MAIN file SYS$USERS:[ECKY]TEST.OBJ;24
> > %LINK-W-USEUNDEF, undefined symbol B referenced
> > in psect $CODE offset %X0000002C
> > in module TEST$MAIN file SYS$USERS:[ECKY]TEST.OBJ;24
> > %LINK-W-USEUNDEF, undefined symbol A referenced
> > in psect $CODE offset %X00000048
> > in module TEST$MAIN file SYS$USERS:[ECKY]TEST.OBJ;24
> > ......
> >
> >
> The EXTERNAL statement says something else will define whatever you are
> referencing. COMMON or MAP is what you want and it has to be in all
> program/subprogram sections. The "MY_DATA" will be the name that is
> shared so it can be whatever you want, it just has to be the same in all
> sections that want to reference it.
> Try this:
> ----------------------------------------
>
> External SUB adder (integer,integer)
> COMMON (MY_DATA) INTEGER a,b
> a=100
> b=200
>
> print "a+b before sub: ",a+b
> call adder (10,20)
> print "a+b after sub: ",a+b
>
> end program
>
> sub adder (integer c,integer d)
> COMMON (MY_DATA) INTEGER a,b
> a=400
> b=1000
> print "a+b in sub: ",a+b
> print "c+d in sub: ",c+d
> end sub
> ------------------------------------------
> Jeff Coffield
> www.digitalsynergyinc.com
Cheers, yeah I went back to Arne's initial suggestion and am backfilling my program accordingly.
Next question to do with arrays. Instead of doing DIM Z(10) it seems I should do COMMON (MY_DATA) INTEGER Z(10) and then use that exact same line within the sub. The 10 and everything has to match. Am I on the right lines there?
Appreciate the help guys!
More information about the Info-vax
mailing list