While playing with pointers, I constructed the following program,
more or less from HELP files, that appears to be correct. When
executed without the MSGBOX statement it terminates without a
problem. No error occurs. When the MSGBOX line is retained, it
seems to provide the correct answer (evidence the program is
correct?), but when the MSGBOX button is clicked a memory
violation error occurs. Is this a compiler bug, or is the
program's use of pointers incorrect.
My PC is a PII system using Windows NT4.0+SP6.
------------------------------------------------------------------
$COMPILE EXE
FUNCTION PBMAIN() AS LONG
DIM R(1:4) AS STRING
R(1)=" String I. ":R(2)=" String II. "
R(3)=" String III. ":R(4)=" String IV. "
DIM xptr(1:4) AS STRING PTR
FOR i&=1 TO 4:xptr(i&)=VARPTR(R(i&)):NEXT
FOR i&=1 TO 4:x$=x$+@xptr(i&)+"|":NEXT
MSGBOX x$ ' without this statement no memory access error occurs
END FUNCTION
more or less from HELP files, that appears to be correct. When
executed without the MSGBOX statement it terminates without a
problem. No error occurs. When the MSGBOX line is retained, it
seems to provide the correct answer (evidence the program is
correct?), but when the MSGBOX button is clicked a memory
violation error occurs. Is this a compiler bug, or is the
program's use of pointers incorrect.
My PC is a PII system using Windows NT4.0+SP6.
------------------------------------------------------------------
$COMPILE EXE
FUNCTION PBMAIN() AS LONG
DIM R(1:4) AS STRING
R(1)=" String I. ":R(2)=" String II. "
R(3)=" String III. ":R(4)=" String IV. "
DIM xptr(1:4) AS STRING PTR
FOR i&=1 TO 4:xptr(i&)=VARPTR(R(i&)):NEXT
FOR i&=1 TO 4:x$=x$+@xptr(i&)+"|":NEXT
MSGBOX x$ ' without this statement no memory access error occurs
END FUNCTION
Comment