Microsoft KB Archive/29923

= FUNCTIONs and Subprograms Can Affect FIELDed Arrays in COMMON =

Article ID: 29923

Article Last Modified on 11/21/2006



This article was previously published under Q29923



SYMPTOMS
An array that is in both a FIELD and a COMMON statement can be adversely affected if you pass it as a parameter to a FUNCTION or subprogram procedure.

The program below has two FIELD statements that result in two arrays pointing to the same memory location. However, after a call to a FUNCTION that should not affect the arrays, they no longer point to the same place in memory. Compiling with debug (BC /D) does not help.



STATUS
Microsoft has confirmed this to be a bug in QuickBasic Versions 4.00, 4.00b, and 4.50, in Microsoft Basic Compiler Versions 6.00 and 6.00b for MS- DOS and MS OS/2, and in Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS and MS OS/2. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
The program works correctly in QuickBasic Version 3.00 if the FUNCTION is made into a subprogram. (QuickBasic Version 3.00 does not support FUNCTION procedures.)

The following is an example using a FUNCTION, but the problem also occurs if the FUNCTION is made into a subprogram: DECLARE FUNCTION Nothing% (any$) DEFINT A-Z COMMON SHARED /GLOBAL/ field1$, field2$ DIM field1$(20), field2$(20) CLS OPEN &quot;anyfile.tmp&quot; FOR RANDOM SHARED AS #1 LEN = 10 FIELD #1, 10 AS field1$(1) FIELD #1, 10 AS field2$(1)

'** NOTE: At this point, field1$(1) and field2$(1) should point to   ** '** the same storage location (buffer space) as verified below. **

LSET field1$(1) = &quot;ABC&quot; PRINT field1$(1); field2$(1) LSET field2$(1) = &quot;DEF&quot; PRINT field1$(1); field2$(1)

x = Nothing(field1$(1))    '** prints field1$ but should not change it. ** 'x = Nothing((field1$(1))) '** passes by value -- this works **

'** Now notice that field1$(1) no longer points to the same storage as ** '** its counterpart, field2$(1), as verified below. **

LSET field1$(1) = &quot;ABC&quot; PRINT field1$(1); field2$(1) LSET field2$(1) = &quot;GHI&quot; PRINT field1$(1); field2$(1) CLOSE END

FUNCTION Nothing (any$) x$ = any$      '** so won't affect value of any$ ** PRINT x$ END FUNCTION

Additional query words: QuickBas buglist4.00 buglist4.00b buglist4.50 buglist6.00 buglist6.00b buglist7.00

Keywords: KB29923

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.