Multi-dimensional array: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 2,660:
</lang>
If you're curious you can use gcc's -S command line option to print out AT&T syntax'd ASM from C/C++ files or something like Cutter if you're more into the Intel syntax.
 
=={{header|XPL0}}==
Arrays can have any number of dimensions.
 
Pointers are used to access beyond the first dimension, thus the concept
of row-major versus column-major doesn't apply. A consequence of this is
that multi-dimensional arrays require more memory than an array in the C
language. Another consequence is that accessing multi-dimensional array
elements can be faster by dereferencing pointers than by calculating
offsets with multiplies. (This was especially true on the 6502 processor
where XPL0 was born.)
 
The last dimension (rightmost index) addresses contiguous memory, for
cache efficiency. Arrays always start at index 0, and there is no
automatic bounds checking. Out-of-bounds errors on multi-dimensional
arrays are very likely to cause memory violation exceptions (segmentation
faults) because of an invalid pointer.
 
Multi-dimensional arrays are supported for all three data types: integer,
real, and character. Multi-dimensional character arrays use 32-bit integer
pointers for each dimension except the last, which are 8-bit bytes.
 
<lang XPL0>
int A(5,4,3,2);
[A(3,1,0,1):= 3100;
A(3,1,0,1):= A(3,1,0,1)+1;
IntOut(0, A(3,1,0,1));
]</lang>
 
{{out}}
<pre>
3101
</pre>
772

edits