KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q51597: In .EXE, PAINT Used in a SUB Can Corrupt Passed Variables

Article: Q51597
Product(s): See article
Version(s): 4.00 4.00b 4.50
Operating System(s): MS-DOS
Keyword(s): ENDUSER | B_BasicCom buglist4.00 buglist4.00b buglist4.50 | mspl13_basic
Last Modified: 6-DEC-1989

The PAINT function can corrupt variables that are passed to a SUB when
the program is compiled using BC.EXE 4.00 4.00B or 4.50. The PAINT
function works correctly in the QB.EXE environment, and if compiled
using BC.EXE with the /X switch.

Microsoft has confirmed this to be a problem in QuickBASIC Versions
4.00, 4.00b, and 4.50 and in Microsoft BASIC Compiler Versions 6.00
and 6.00b (buglist6.00 buglist6.00b) for MS-DOS. This problem was
corrected in Microsoft BASIC Compiler Version 7.00 (fixlist7.00).

The following program demonstrates this problem. The values of x and y
will be invalid following the PAINT(x, y) statement; however, the
values of x and y are unaffected at the module level code following
the call to "Sub1":

Compile with either: BC Paint; or BC Paint /O;
Link with:           Link Paint;

Code Example: PAINT.BAS
-----------------------

DECLARE SUB Sub1(x,y)
x = 300                'Initialize x
y = 100                'Initialize y
CALL Sub1(x,y)
PRINT x; y             'These values will be correct
END
SUB Sub1 (x, y)
SCREEN 12              'Any graphics mode
PRINT x; y             'These values will be correct
CIRCLE (x, y), 50
PAINT (x, y)            'Paint the circle
PRINT x; y             '** These values will contain garbage
END SUB

Specifying a definite type for x and y (such as INTEGER, LONG, SINGLE,
or DOUBLE) does not have any effect on the output.

Four possible workarounds for the PAINT problem are as follows:

1. Compile with BC /X.

2. Copy x and y to variables that are local to the SUB.

3. PAINT at the module level instead of at the SUB level.

4. Make x and y SHARED or COMMON SHARED.

This problem was corrected in Microsoft BASIC Compiler 7.00.

Additional reference word: SR# S891128-117

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.