Automatic Index Padding

Unlike its automatically dereferenced pointers, VTS's automatically padded indices makes for array-related code that looks the same, but behaves differently, depending on whether a dynamic array or a static array is used. This mismatch between appearance and workings can easily lead to developer confusion, and thus warrants special attention.

VTS applies automatic index padding whenever an array reference is under-specified. In turn, an array reference is considered under-specified if two criteria are met:

1.  The array reference must involve an array value, as opposed to a pointer to an array value. This is almost the same as saying the array reference must involve a static array variable, as opposed to a dynamic array variable, with two exceptions:

a.  Whenever a dynamic array variable is explicitly dereferenced (*DynamicArray), the result is an array value.

b.  Similarly, whenever a dynamic array is referenced with the [ ] operator, VTS automatically dereferences the array pointer, and the result is an array value.

2.  An array reference must include fewer [ ] operators than the referenced array has dimensions.

Given a two-dimensional dynamic array variable named, DynamicArray, and a two-dimensional static array variable named, StaticArray, the following code demonstrates under-specification:

1. *DynamicArray;  { Under specified }

2. DynamicArray;  { Not under-specified, not an array value }

3. DynamicArray[2];  { Under-specified, automatic dereferencing }

4. DynamicArray[1][3]; { Not under-specified }

5. StaticArray;  { Under-specified }

6. &StaticArray;  { Not under-specified, not an array value }

7. StaticArray[2];  { Under-specified }

8. StaticArray[1][3]; { Not under-specified }

Lines 2 and 5 demonstrate the inconspicuous difference between dynamic and static arrays: VTS considers line 2 fully specified, but considers line 5 under-specified.

Whenever VTS encounters an under-specified array reference, it automatically pads the least significant, under-specified indices with zero indices. Revisiting the example above, the array references are padded as indicated by the comments in the code below.

x = *DynamicArray;  { x = DynamicArray[0][0] }

x = DynamicArray;  { x = DynamicArray. See Variable Assignment below }

x = DynamicArray[2]; { x = DynamicArray[2][0] }

x = DynamicArray[1][3]; { x = DynamicArray[1][3] }

x = StaticArray;  { x = StaticArray[0][0] }

x = &StaticArray;  { x = StaticArray. See Variable Assignment below }

x = StaticArray[2];  { x = StaticArray[2][0] }

x = StaticArray[1][3]; { x = StaticArray[1][3] }