Q34283: BC Hangs on a POKE with a FUNCTION Passed a Dynamic Array
Article: Q34283
Product(s): See article
Version(s): 4.00 4.00b
Operating System(s): MS-DOS
Keyword(s): ENDUSER | buglist4.00 buglist4.00b fixlist4.50 B_BasicCom | mspl13_basic
Last Modified: 11-DEC-1989
BC.EXE hangs at compile time when compiling the program below. This
program uses a POKE statement that directly invokes a FUNCTION
procedure that is passed a dynamic-array element as an argument.
Microsoft has confirmed this to be a problem in Microsoft QuickBASIC
Versions 4.00 and 4.00b and in Microsoft BASIC Compiler Versions 6.00
and 6.00b for MS-DOS and MS OS/2 (buglist6.00 and buglist6.00b). This
problem has been corrected in QuickBASIC Version 4.50 and in
Microsoft BASIC Compiler Version 7.00 (fixlist7.00).
The following are several workarounds for this problem:
1. Make the array STATIC instead of DYNAMIC.
2. Use a temporary variable to pass the array element to the FUNCTION
procedure.
3. Use a temporary variable to receive the value returned from the
FUNCTION and POKE that temporary variable.
Note that Page 201 of the "Microsoft QuickBASIC 4.0: BASIC Language
Reference" manual gives the following related information:
"Because BASIC may rearrange arithmetic expressions for
greater efficiency, avoid using FUNCTION procedures that
change program variables in arithmetic expressions."
The following code example demonstrates the problem:
REM This program demonstrates the problem at compile-time in BC.EXE
DEFINT A-Z
DECLARE FUNCTION charOff (row)
REM $DYNAMIC
DIM SHARED a(4) AS INTEGER
' Poke a value returned by a function that is passed a dynamic
' array element:
POKE charOff(a(1)), 210
END
FUNCTION charOff (row)
END FUNCTION
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.