Microsoft KB Archive/48401

= Multi-DIMensioned Arrays Are in Column Order; BC /R Row Order =

Article ID: 48401

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q48401



SUMMARY
By default, multidimensional arrays are stored in contiguous columns in memory (that is, column-major order) in compiled Basic. With column-major order, the leftmost subscript (the row dimension) changes the fastest.

You can force executable .EXE programs to store arrays in rows by using the BC /R option. However, the /R option (for row-major order) is not available in the QB.EXE or the QBX.EXE editor environment. With row-major order, the rightmost subscript (the column dimension) changes the fastest.



MORE INFORMATION
In the DIM X(row,column) statement, arrays are stored by default in column order in memory. When looking at a contiguous block of memory that is storing a two-dimensional array, you'll find one column stored after another. For example, for DIM X(2,2), the array elements are stored by default in the following column-major order:   X(0,0), X(1,0), X(2,0), X(0,1), X(1,1), X(2,1), X(0,2), X(1,2), X(2,2) If you compile the program with BC /R, you get row-major order, as follows:   X(0,0), X(0,1), X(0,2), X(1,0), X(1,1), X(1,2), X(2,0), X(2,1), X(2,2) An easy way to demonstrate the storage order is to BSAVE a two- dimensional array and then BLOAD the same data into a one-dimensional array. You then have a firsthand view of how the array is stored.

Unlike Basic, Microsoft C defaults to row-major order.

This array-order information is taken from Page 313 of the &quot;Microsoft QuickBasic 4.0: Learning and Using&quot; manual for QuickBasic Versions 4.00 and 4.00b, from Page 313 of the &quot;Microsoft Basic Compiler 6.0: Learning and Using Microsoft QuickBasic&quot; manual for Versions 6.00 and 6.00b, and from Page 560 of the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; for Basic PDS Version 7.00.

Additional query words: QuickBas BasicCom

Keywords: KB48401

-

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

© Microsoft Corporation. All rights reserved.