SHARED Dynamic Array Element Passed as Parameter Aliases to 0 (47566)
The information in this article applies to:
- Microsoft QuickBASIC 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBASIC 4.5
- Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
- Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
- Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
This article was previously published under Q47566 SUMMARY
If you attempt to alter an element of a SHARED or COMMON SHARED
$DYNAMIC array while inside a SUBprogram and that element has also
been passed as a parameter to the SUBprogram, the value returned in
the parameter will be the value assigned to the array element upon
exit from the SUBprogram, and will replace whatever value may have
been assigned directly to the array in the SUBprogram.
This behavior occurs in Microsoft QuickBasic versions 4.00, 4.00b, and
4.50, Microsoft Basic Compiler 6.00 and 6.00b for MS-DOS and MS OS/2,
and Microsoft Basic PDS 7.00 for MS-DOS and MS OS/2.
This is a form of variable aliasing, which is a programming practice
not recommended by Microsoft. A variable passed in an argument list to
a procedure should not also be shared by means of the SHARED statement
or the SHARED attribute (of the DIM or COMMON statement) in that
procedure's module.
Similarly, a variable should not be passed twice in the list of
arguments passed to a procedure, or else variable aliasing problems
occur. This information can be found under "The Problem of Variable
Aliasing" section, on Page 64 in the "Microsoft Basic 7.0:
Programmer's Guide" for Basic PDS versions 7.00 and 7.10, on Page 68
of the "Microsoft QuickBasic 4.5: Programming in Basic" manual, and on
Page 78 of "Microsoft QuickBasic 4.0: Programming in Basic: Selected
Topics" manual for versions 4.00 and 4.00b.
Modification Type: | Minor | Last Reviewed: | 1/9/2003 |
---|
Keywords: | KB47566 |
---|
|