Discussion:
VAX BASIC global variables.
(too old to reply)
Arne Vajhøj
2021-10-15 00:40:26 UTC
Permalink
I come from BBC Basic where all variables are global unless
explicitly defined as local to a sub/proc.
VAX BASIC seems to operate the opposite way; IE variables by default
are local. QB64 also seems to operate this way however in QB64, I am
able to DIM SHARED [var_name] which makes a variable accessible
globally.
How do I accomplish the same in VAX BASIC? I want a variable declared
at the top to be common throughout all the code, SUBs and all. At
this time, I'm working with a single source file.
I'm looking at the COMMON keyword but I can't see how that works for
what I want, if at all it does!
program comdemo
common (myarea) integer v
v = 1
call s1
end program
sub s1
common (myarea) integer v
v = v + 1
call s2
end sub
sub s2
common (myarea) integer v
v = v + 1
print v
end sub
And no - I don't know Basic, but I know Fortran, so I just
coded Fortran in Basic.

:-)

program comdemo
integer*4 v
common /myarea/v
v = 1
call s1
end
c
subroutine s1
integer*4 v
common /myarea/v
v = v + 1
call s2
return
end
c
subroutine s2
integer*4 v
common /myarea/v
v = v + 1
write(*,*) v
return
end

Arne
E Thump
2021-10-15 01:18:56 UTC
Permalink
I come from BBC Basic where all variables are global unless
explicitly defined as local to a sub/proc.
VAX BASIC seems to operate the opposite way; IE variables by default
are local. QB64 also seems to operate this way however in QB64, I am
able to DIM SHARED [var_name] which makes a variable accessible
globally.
How do I accomplish the same in VAX BASIC? I want a variable declared
at the top to be common throughout all the code, SUBs and all. At
this time, I'm working with a single source file.
I'm looking at the COMMON keyword but I can't see how that works for
what I want, if at all it does!
program comdemo
common (myarea) integer v
Alright, thanks so I was on the right track with COMMON... what's the significance of myarea then?

I changed my program to this but it doesn't work as I want:
=====
External SUB adder (integer,integer)

common (myarea) integer a
common (myarea) integer 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
=====
yields:

a+b before sub: 300
a+b in sub: 1400
c+d in sub: 30
a+b after sub: 300
Arne Vajhøj
2021-10-15 01:24:50 UTC
Permalink
Post by E Thump
program comdemo
common (myarea) integer v
Alright, thanks so I was on the right track with COMMON... what's the significance of myarea then?
That is the name of the memory area.

And it is really what matters!

Which becomes clear by the fact that this also print 3:

program comdemo2
common (myarea) integer v
v = 1
call s1
end program

sub s1
common (myarea) integer w
w = w + 1
call s2
end sub

sub s2
common (myarea) integer u
u = u + 1
print u
end sub
Post by E Thump
=====
External SUB adder (integer,integer)
common (myarea) integer a
common (myarea) integer b
I would make that:

common (myarea) integer a,b
Post by E Thump
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
You do not have a common (myarea) in adder, so it does
not use anything global.

Arne
Arne Vajhøj
2021-10-15 01:26:15 UTC
Permalink
Post by Arne Vajhøj
Post by E Thump
=====
External SUB adder (integer,integer)
common (myarea) integer a
common (myarea) integer b
common (myarea) integer a,b
Post by E Thump
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
You do not have a common (myarea) in adder, so it does
not use anything global.
External SUB adder (integer,integer)

common (myarea) 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 (myarea) integer a,b
a=400
b=1000
print "a+b in sub: ",a+b
print "c+d in sub: ",c+d
end sub

Arne
E Thump
2021-10-15 01:30:38 UTC
Permalink
Post by Arne Vajhøj
You do not have a common (myarea) in adder, so it does
not use anything global.
Arne
Aaah... forgive me... it's 2.30am here!!

I missed that. I tried it and it works in my program. The second 'after sub' prints 1400 now.

OK, I think I get it. I'll re-read the docs with this new knowledge, hopefully it'll make a bit more sense.

thanks much!
e
Arne Vajhøj
2021-10-15 01:33:42 UTC
Permalink
Post by E Thump
Post by Arne Vajhøj
You do not have a common (myarea) in adder, so it does
not use anything global.
Aaah... forgive me... it's 2.30am here!!
I missed that. I tried it and it works in my program. The second 'after sub' prints 1400 now.
OK, I think I get it. I'll re-read the docs with this new knowledge, hopefully it'll make a bit more sense.
And remember this is just the Fortran way.

Maybe there is better way in Basic.

But that will require somebody that knows Basic. Like Dave or the VSI
compiler guru.

Arne
Stephen Hoffman
2021-10-15 02:29:49 UTC
Permalink
Any VAX BASIC folk here?
Really VAX BASIC, and not BASIC on OpenVMS VAX with the
DEC/Compaq/HP/HPE/VSI BASIC compiler?

DEC/Compaq/HP/HPE/VSI BASIC replaced VAX BASIC a very long time ago
(back in VAX/VMS V3.x, IIRC)...

Assuming this is not the archaic VAX BASIC compiler, but rather the
DEC/Compaq/HP/HPE BASIC compiler...

https://vmssoftware.com/docs/VSI_BASIC_USER.pdf
https://vmssoftware.com/docs/VSI_BASIC_REF.pdf

The keyword you're looking for is EXTERNAL. See page 105 in the
reference manual, linked above.

COMMON (reference manual page 67) is not what you want.
--
Pure Personal Opinion | HoffmanLabs LLC
E Thump
2021-10-15 09:42:54 UTC
Permalink
Post by Stephen Hoffman
Any VAX BASIC folk here?
Really VAX BASIC, and not BASIC on OpenVMS VAX with the
DEC/Compaq/HP/HPE/VSI BASIC compiler?
DEC/Compaq/HP/HPE/VSI BASIC replaced VAX BASIC a very long time ago
(back in VAX/VMS V3.x, IIRC)...
Assuming this is not the archaic VAX BASIC compiler, but rather the
DEC/Compaq/HP/HPE BASIC compiler...
https://vmssoftware.com/docs/VSI_BASIC_USER.pdf
https://vmssoftware.com/docs/VSI_BASIC_REF.pdf
The keyword you're looking for is EXTERNAL. See page 105 in the
reference manual, linked above.
COMMON (reference manual page 67) is not what you want.
--
Pure Personal Opinion | HoffmanLabs LLC
It identifies as "VAX BASIC V3.8-000" when I start it. Came with my uVAX3100-80 running OpenVMS 6.2

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
......
Arne Vajhøj
2021-10-15 15:18:57 UTC
Permalink
Post by E Thump
Post by Stephen Hoffman
The keyword you're looking for is EXTERNAL. See page 105 in the
reference manual, linked above.
COMMON (reference manual page 67) is not what you want.
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
%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
......
You need them defined somewhere.

I don't know how to make a symbol global in Basic.

It is easy in C:

$ type extdemo.bas
program extdemo
external integer v
v = 1
call s1
end program

sub s1
external integer v
v = v + 1
call s2
end sub

sub s2
external integer v
v = v + 1
print v
end sub
$ bas extdemo
$ type v.c
int v;
$ cc v
$ link extdemo + v
$ r extdemo
3

Arne
Jeffrey H. Coffield
2021-10-15 15:44:45 UTC
Permalink
Post by E Thump
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
%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
E Thump
2021-10-15 16:09:40 UTC
Permalink
Post by Jeffrey H. Coffield
Post by E Thump
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
%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.
----------------------------------------
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!
Arne Vajhøj
2021-10-15 16:56:19 UTC
Permalink
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.

Declarations *should* match.

They are not strictly required to, but it becomes
pretty messy if they don't.

This does not look good:

program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program

sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub


Arne
Arne Vajhøj
2021-10-15 17:27:15 UTC
Permalink
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
So better include:

$ type common.bas
common (mydata) long a(2)
$ type better.bas
program better
%include "common.bas"
call s
print a(0),a(1)
end program

sub s
%include "common.bas"
a(0) = 1
a(1) = 2
end sub
$ bas better
$ lin better
$ run better
1 2

Arne
Dave Froble
2021-10-15 19:05:51 UTC
Permalink
Post by Arne Vajhøj
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
$ type common.bas
common (mydata) long a(2)
$ type better.bas
program better
%include "common.bas"
call s
print a(0),a(1)
end program
sub s
%include "common.bas"
a(0) = 1
a(1) = 2
end sub
$ bas better
$ lin better
$ run better
1 2
Arne
Yes, it works. I tend to avoid COMMON unless I really need it.

Note that the address of a RECORD structure can be passed as a parameter.
Quite useful.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
Simon Clubley
2021-10-15 17:40:24 UTC
Permalink
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
Yuck. :-)

Common belongs back in the Fortran IV days. Please tell me that DEC Basic
supports user-defined record data types and that you can pass references
to instances of those data types around as subroutine parameters. :-)
Post by Arne Vajhøj
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
Simon.
--
Simon Clubley, ***@remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.
Arne Vajhøj
2021-10-15 17:47:09 UTC
Permalink
Post by Simon Clubley
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
Yuck. :-)
Common belongs back in the Fortran IV days.
Not really.

Most languages got a capability to expose some global variable.

C style of exposing each individual variable instead
of a named block is just a bit more primitive.
Post by Simon Clubley
Please tell me that DEC Basic
supports user-defined record data types and that you can pass references
to instances of those data types around as subroutine parameters. :-)
It does.

But passing as arguments vs using global variables and operating
on individual variables vs operating on records are two independent
questions.

Arne
Dave Froble
2021-10-15 19:10:06 UTC
Permalink
Post by Simon Clubley
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
Yuck. :-)
Common belongs back in the Fortran IV days. Please tell me that DEC Basic
supports user-defined record data types and that you can pass references
to instances of those data types around as subroutine parameters. :-)
Yes, as I just mentioned elsewhere. I really like it, and use it whenever appropriate.

The RECORD statement.

RECORD SIMON
Long A%
String B$
END RECORD

DIM SIMON Dave(5)

And now Dave(0)::A% is the address of the structure.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
Lawrence D’Oliveiro
2021-10-15 22:14:37 UTC
Permalink
Post by Simon Clubley
Common belongs back in the Fortran IV days.
But, consider that in C, every extern variable is effectively its own named common block.

With all that that implies.
Lawrence D’Oliveiro
2021-10-15 22:36:40 UTC
Permalink
Post by Lawrence D’Oliveiro
But, consider that in C, every extern variable is effectively its own named common block.
With all that that implies.
Umm, maybe I was thinking of K&R C ...
Arne Vajhøj
2021-10-16 00:14:27 UTC
Permalink
Post by Lawrence D’Oliveiro
Post by Lawrence D’Oliveiro
But, consider that in C, every extern variable is effectively its own named common block.
With all that that implies.
Umm, maybe I was thinking of K&R C ...
VAX C used that model.

DEC/CPQ/HP(E)/VSI C by default use another model, but can
use that model if instructed to (/EXTERN=COMMON/SHARE).

Arne
Dave Froble
2021-10-15 19:03:41 UTC
Permalink
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
Arne
In Arne's example, the linker will allocate space for the 4 element array,
but the main program will not be able to address a(3).
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
Arne Vajhøj
2021-10-15 19:13:21 UTC
Permalink
Post by Dave Froble
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
In Arne's example, the linker will allocate space for the 4 element array,
but the main program will not be able to address a(3).
It runs fine.

And outputs exactly what I expected.

$ bas hack
$ lin hack
$ run hack
65537 131074

(which is 00010001 and 00020002 in hex)

But definitely not nice.

Arne
Dave Froble
2021-10-15 20:37:01 UTC
Permalink
Post by Arne Vajhøj
Post by Dave Froble
Post by Arne Vajhøj
Post by E Thump
Post by Jeffrey H. Coffield
COMMON (MY_DATA) INTEGER a,b
sub adder (integer c,integer d)
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?
Yes.
Declarations *should* match.
They are not strictly required to, but it becomes
pretty messy if they don't.
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
In Arne's example, the linker will allocate space for the 4 element array,
but the main program will not be able to address a(3).
It runs fine.
And outputs exactly what I expected.
$ bas hack
$ lin hack
$ run hack
65537 131074
(which is 00010001 and 00020002 in hex)
But definitely not nice.
I see my reading skills are deteriorating, like the rest of me. I missed the
LONG vs WORD. I thought you were defining different size common blocks.

And a(4) is a 5 element array, not 4 as I stated elsewhere.

Re-defining a storage location can be useful.

MAP (Z) LONG A%
MAP (Z) String A$=4
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
Arne Vajhøj
2021-10-16 00:18:58 UTC
Permalink
Post by Arne Vajhøj
Post by Dave Froble
Post by Arne Vajhøj
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
In Arne's example, the linker will allocate space for the 4 element array,
but the main program will not be able to address a(3).
It runs fine.
And outputs exactly what I expected.
$ bas hack
$ lin hack
$ run hack
 65537         131074
(which is 00010001 and 00020002 in hex)
But definitely not nice.
I see my reading skills are deteriorating, like the rest of me.  I
missed the
LONG vs WORD.  I thought you were defining different size common blocks.
N. I was doing different types.
And a(4) is a 5 element array, not 4 as I stated elsewhere.
Ah. So it should have been a(1) and a(3). Not totally like Fortran.

Arne
Dave Froble
2021-10-16 01:08:46 UTC
Permalink
Post by Arne Vajhøj
Post by Dave Froble
Post by Arne Vajhøj
Post by Dave Froble
Post by Arne Vajhøj
program hack
common (mydata) long a(2)
call s
print a(0),a(1)
end program
sub s
common (mydata) word a(4)
a(0) = 1
a(1) = 1
a(2) = 2
a(3) = 2
end sub
In Arne's example, the linker will allocate space for the 4 element array,
but the main program will not be able to address a(3).
It runs fine.
And outputs exactly what I expected.
$ bas hack
$ lin hack
$ run hack
65537 131074
(which is 00010001 and 00020002 in hex)
But definitely not nice.
I see my reading skills are deteriorating, like the rest of me. I missed the
LONG vs WORD. I thought you were defining different size common blocks.
N. I was doing different types.
Post by Dave Froble
And a(4) is a 5 element array, not 4 as I stated elsewhere.
Ah. So it should have been a(1) and a(3). Not totally like Fortran.
Arne
One can set upper and lower bounds on an array. I never have.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
Lawrence D’Oliveiro
2021-10-16 01:32:31 UTC
Permalink
One can set upper and lower bounds on an array. I never have.
I probably did in my Pascal days.

More recently, one thing I can remember writing (along those lines) is this <http://www.codecodex.com/wiki/Convert_an_integer_into_words> (the Algol 68 version).

(OK, it was just the “decades” array...)
Arne Vajhøj
2021-10-16 02:01:17 UTC
Permalink
Post by Lawrence D’Oliveiro
One can set upper and lower bounds on an array. I never have.
I probably did in my Pascal days.
Unless your Pascal days was extremely limited you probably did.

(lower and upper bounds are mandatory in Pascal)

Arne
Dave Froble
2021-10-15 19:01:26 UTC
Permalink
Post by E Thump
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!
Is there some reason you're wanting global variables? Yes, they can be useful, but there
are other methods to pass variables between programs.

As Jeff mentioned, COMMON and MAP are the methods to have global data, and, they must be
defined everywhere referenced. Both are set up as a PSECT. The linker aligns them. I won't
get into having different definitions of the structure. That can get interesting.

You can pass an array to a subprogram or function. After all, parameters are just an address
or a value.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
Stephen Hoffman
2021-10-15 16:42:41 UTC
Permalink
Post by E Thump
Post by Stephen Hoffman
Any VAX BASIC folk here?
Really VAX BASIC, and not BASIC on OpenVMS VAX with the
DEC/Compaq/HP/HPE/VSI BASIC compiler?
DEC/Compaq/HP/HPE/VSI BASIC replaced VAX BASIC a very long time ago
(back in VAX/VMS V3.x, IIRC)...
Assuming this is not the archaic VAX BASIC compiler, but rather the
DEC/Compaq/HP/HPE BASIC compiler...
https://vmssoftware.com/docs/VSI_BASIC_USER.pdf
https://vmssoftware.com/docs/VSI_BASIC_REF.pdf
The keyword you're looking for is EXTERNAL. See page 105 in the
reference manual, linked above.
COMMON (reference manual page 67) is not what you want.
--
Pure Personal Opinion | HoffmanLabs LLC
It identifies as "VAX BASIC V3.8-000" when I start it. Came with my
uVAX3100-80 running OpenVMS 6.2
V7.3 with whatever the latest BASIC for that era might be is the usual
recommendation.

I will assume the usual 'must experience all the associated bugs and
issues and limits of the oldest config' applies here.

I'm not going to wade through the old installer kits to figure out how
ancient that BASIC is. It's ancient.

I'd forgotten about the problems with the BASIC manuals. They're really
not very good. Ah, well.
Post by E Thump
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
%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
......
Assuming that's all one source code module (showing your commands helps
us figure out the details of your tests), you've told BASIC ADDER, A,
and B are all EXTERNAL, and they're all in one source module; there are
no EXTERNAL references, and (what the LINKER is telling you) no
declarations. If you're trying to break the BASIC-preferrred
modular-programming model within your app—I'd assumed that wasn't your
goal (as that approach turns gnarly), but looking at the source code
again, that does appear to be what you want to do—then using COMMON is
one way to do that. I'd still keep clear of COMMON storage, as that
usually ends badly as the apps increase in scale and complexity.


$ TYPE EXAMPLE.BAS
OPTION TYPE=EXPLICIT
DECLARE LONG 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
$ BASIC EXAMPLE
$ LINK EXAMPLE
$ RUN EXAMPLE
a+b before sub: 300
a+b in sub: 1400
c+d in sub: 33984
a+b after sub: 300
$
$
$ TYPE COMMON.BAS
OPTION TYPE=EXPLICIT
COMMON (HACK) LONG 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 (HACK) LONG A, B
a=400
b=1000
print "a+b in sub: ",a+b
print "c+d in sub: ",c+d
end sub
$ BASIC COMMON
$ LINK COMMON
$ RUN COMMON
a+b before sub: 300
a+b in sub: 1400
c+d in sub: 33984
a+b after sub: 1400
$
--
Pure Personal Opinion | HoffmanLabs LLC
Jeffrey H. Coffield
2021-10-15 17:32:18 UTC
Permalink
Hi -
Any VAX BASIC folk here?
Need some help - am new to VAX BASIC (yeah, in 2021!!)
I come from BBC Basic where all variables are global unless explicitly defined as local to a sub/proc.
VAX BASIC seems to operate the opposite way; IE variables by default are local. QB64 also seems to operate this way however in QB64, I am able to DIM SHARED [var_name] which makes a variable accessible globally.
How do I accomplish the same in VAX BASIC? I want a variable declared at the top to be common throughout all the code, SUBs and all. At this time, I'm working with a single source file.
I'm looking at the COMMON keyword but I can't see how that works for what I want, if at all it does!
Cheers,
e
I guess the real question for me is what do you want to do with Basic?

Jeff Coffield
www.digitalsynergyinc.com
E Thump
2021-10-15 18:21:49 UTC
Permalink
Post by Jeffrey H. Coffield
I guess the real question for me is what do you want to do with Basic?
Jeff Coffield
www.digitalsynergyinc.com
Good question!

There's a particular program, an adventure game by Acornsoft released in 1982 or 1983. I recently discovered that it was written in BASIC. I'm just trying to convert it to as many different platforms and implementations of BASIC as I can.

I've already got it going in QB64 on my Linux box. Next target is my VAX. I'm also looking to port it to Amiga, ST with GFA, Amos etc.

All just for fun - nothing serious :)
Tad Winters
2021-10-16 03:26:20 UTC
Permalink
I don't know BASIC, but VAX DIBOL uses:

GLOBAL COMMON variable-name

to define a variable common across routine, and ordinarily in the main
program. It then uses:

EXTERNAL COMMON variable-name

to make reference to the same memory location as the one defined by
global common. My first guess is that it is close to the same in BASIC.

Good luck with your project.

Loading...