Discussion:
Interesting Gotcha in BASIC
(too old to reply)
Alan Adams
2019-05-26 12:20:43 UTC
Permalink
Hi

I've been tearing my hair out over a weird misbehaviour in one of my BASIC
programs. As it's an interersting trap to fall into, I thought it worth
sharing.

The program begine

DIM ablock% 1024 bbloak% 1024

Then

ablock%!0 = windowhandle1%
PROCopenwindows(ablock%)

Openwondows manages a main and a pane window, and uses the two memory
blcoks to keep track of data about the two windows

DEF PROCopenwindows(bblock%)
SYS "Wimp_GetWindowState",,bblock%

all good so far

!ablock%=windowhandle2%
SYS "Wimp_GetWinDowState",,ablock%

bblock% now contains data about the wrong window.

The reason is that passing ablock% in as a parameter canses the two block
variables within the procedure to hold the same address.
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
Alan Adams
2019-05-26 12:21:54 UTC
Permalink
Post by Alan Adams
Hi
I've been tearing my hair out over a weird misbehaviour in one of my BASIC
programs. As it's an interersting trap to fall into, I thought it worth
sharing.
The program begine
DIM ablock% 1024 bbloak% 1024
Then
ablock%!0 = windowhandle1%
PROCopenwindows(ablock%)
Openwondows manages a main and a pane window, and uses the two memory
blcoks to keep track of data about the two windows
DEF PROCopenwindows(bblock%)
SYS "Wimp_GetWindowState",,bblock%
all good so far
!ablock%=windowhandle2%
SYS "Wimp_GetWinDowState",,ablock%
bblock% now contains data about the wrong window.
The reason is that passing ablock% in as a parameter canses the two block
variables within the procedure to hold the same address.
and the DIM should be

DIM ablock% 1024, bblock% 1024, i.e. spelling error and missing comma.
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
Loading...