BC /R Makes UBOUND and LBOUND Incorrect for Multi-DIM Array (65402)
This article was previously published under Q65402
SYMPTOMS
The UBOUND and LBOUND functions return the upper and lower bounds of
an array. However, if a program is compiled using the BC /R compiler
option, which stores multidimensional arrays in row major order, the
UBOUND and LBOUND functions return incorrect dimension bounds for
multidimensional arrays.
STATUS
Microsoft has confirmed this to be a bug in the BC /R option in
QuickBasic versions 4.00, 4.00b, and 4.50 (buglist4.00, buglist4.00b,
buglist4.50) for MS-DOS; 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) versions 7.00 and 7.10 for MS-DOS and OS/2.
Microsoft is researching this problem and will post new information
here in the Microsoft Knowledge Base as it becomes available.
Note that by default (without the /R option), BC.EXE stores arrays in
column major order, and the UBOUND and LBOUND functions return correct
values. Note also that the /R switch cannot be used within QBX.EXE;
therefore, QBX.EXE can only store arrays in column major order. UBOUND
and LBOUND work correctly in QBX.EXE.
MORE INFORMATION
For more information on using the BC /R compiler switch, query in this
Knowledge Base on the following words:
MULTIDIMENSIONAL AND COLUMN AND ROW AND MAJOR
Although the array is stored differently in memory by the /R compiler
option, the upper and lower bounds of each dimension do not change.
Therefore the values returned by UBOUND and LBOUND for a given
dimension are supposed to be the same compiling with or without BC /R.
When a program is compiled with the BC /R switch, the UBOUND and
LBOUND (for a given dimension) incorrectly return the bounds for the
opposite dimension. For example, in a two-dimensional array, if you
request the UBOUND and LBOUND values for the first dimension, the
values returned will incorrectly be those of the second dimension.
Requesting the UBOUND and LBOUND values for the second dimension
incorrectly gives you the bounds for the first dimension.
In an odd-dimensioned array, UBOUND and LBOUND return correct bounds
for the middle dimension, but incorrect bounds for all other
dimensions when compiled BC /R. For example, in a three-dimensional
array, UBOUND and LBOUND for the first dimension incorrectly return
bounds for the third dimension; UBOUND and LBOUND for the third
dimension incorrectly return bounds for the first dimension; but
UBOUND and LBOUND for the second dimension correctly return bounds for
the second dimension.
Code Example
The following program example demonstrates the problem:
DIM A(-1 TO 1, -2 TO 2) ' DIMensions A() as a 2-dimensional array.
' Print lower and upper bound of first dimension:
PRINT LBOUND(A, 1), UBOUND(A, 1)
' Print lower and upper bound of second dimension:
PRINT LBOUND(A, 2), UBOUND(A, 2)
Output when compiled without BC /R (correct):
-1 1
-2 2
Output when compiled with BC /R (incorrect):
-2 2
-1 1
Modification Type: |
Minor |
Last Reviewed: |
1/8/2003 |
Keywords: |
KB65402 |
|