Microsoft KB Archive/57925

= Array Elements Are Passed in Temporary Variables for BC /D =

Article ID: 57925

Article Last Modified on 11/21/2006



This article was previously published under Q57925



SUMMARY
In a program compiled with the BC /D debug switch, array elements that are passed to a SUB or FUNCTION are passed using temporary variables. A program that is not compiled with the /D debug switch passes actual array elements and does not use temporary variables.

When using the /D debug switch, taking the VARSEG and VARPTR of an array element in the module level code returns the address of the array element in memory. However, when taking the VARSEG and VARPTR of the array element once it has been passed as a parameter to a SUB or FUNCTION, VARSEG and VARPTR return the address of the temporary variable that the array element is stored in.

In addition, a program that is being run in the QB.EXE or QBX.EXE environment passes array elements using temporary variables since debug mode is always on in the environment.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS and MS OS/2.



MORE INFORMATION
The following sample program demonstrates how Basic uses temporary variables when passing array elements to a SUB or FUNCTION when compiled with the /D debug option: DIM A%(100) A%(1) = 1

PRINT &quot;The address of the array element before the call&quot; PRINT VARSEG(A%(1)), VARPTR(A%(1)) CALL subtest(A%(1)) PRINT &quot;The address of the array element after the call&quot; PRINT VARSEG(A%(1)), VARPTR(A%(1))

SUB subtest(tempvar%) PRINT &quot;The address of the array element during the call&quot; PRINT &quot;This address should be different if using /D debug switch&quot; PRINT VARSEG(tempvar%), VARPTR(tempvar%) END SUB Compile and link the code as follows: BC /d Test.bas; LINK Test.bas;

Additional query words: QuickBas BasicCom

Keywords: KB57925

-

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

© Microsoft Corporation. All rights reserved.