An application variable is usually a scalar quantity (a single character, integer, or floating-point value). The variable appears in the Watch window with the variable name to the left, followed by an equal sign (=) and the current value.
The Watch window provides a different way to display aggregate data items, such as arrays and structures. Arrays and structures contain multiple values that can be arranged in one or more layers. You can control how these variables appear in the Watch window—whether all, part, or none of their internal structure is displayed.
For example, the array WordHolder initially appears in the Watch window in the following form:
+WordHolder[] = [...]
The brackets indicate that this variable contains more than one element. The plus sign (+) indicates that the variable has more elements than are displayed on the screen. You can expand the variable to display any or all of its components; this technique is called dereferencing.
To dereference (expand) the array, you can double-click anywhere on the displayed line or you can position the cursor on the line and press ENTER. For example, if WordHolder is a six-character array containing the word Basic, the Watch window display changes to the following:
-WordHolder[]
[0] = 66 'B'
[1] = 97 'a'
[2] = 115 's'
[3] = 105 'i'
[4] = 99 'c'
[5] = 0 ''
Note that both the individual character values and their ASCII decimal equivalents are listed. The minus sign (-) indicates that no further expansion is possible. To contract the array, you can double-click its line again or you can position the cursor on the line and press ENTER.
If viewing a character array in this form is inconvenient, use either of the following methods to specify the watchpoint:
Type the variable name, a comma (,), and the letter s, as shown in the following example:
WordHolder,s
CVW displays the contents of the array, as follows:
WordHolder,s[] = "Basic"
Cast the variable's name to a character pointer, as shown in the following example:
(char *)WordHolder
CVW displays the address of the array and its contents, as follows:
(char *)WordHolder = 0x8C7:0x0010 "Basic"
You can display an array with more than one dimension. For example, imagine an integer array (5 by 5) named Matrix, whose diagonal elements are the numbers 1 through 5 and whose other elements are zero. Unexpanded, the array is displayed like this:
+Matrix[] = [...]
Double-click on the word Matrix (or position the cursor on that line and press ENTER) to change the display to the following:
-Matrix[]
+[0][] = [...]
+[1][] = [...]
+[2][] = [...]
+[3][] = [...]
+[4][] = [...]
The actual values of the elements are not shown yet. You have to descend one more level to see them. For example, to view the elements of the third row of the array, position the cursor anywhere on its subscript line (the +[2] line) and press ENTER. The following example shows the third row of the array dereferenced:
-Matrix[]
+[0][] = [...]
+[1][] = [...]
-[2][]
[0] = 0
[1] = 0
[2] = 3
[3] = 0
[4] = 0
+[3][] = [...]
+[4][] = [...]
Dereferencing the fifth row (+[4]) of the array produces this display:
-Matrix[]
+[0][] = [...]
+[1][] = [...]
-[2][]
[0] = 0
[1] = 0
[2] = 3
[3] = 0
[4] = 0
+[3][] = [...]
-[4][]
[0] = 0
[1] = 0
[2] = 0
[3] = 0
[4] = 5
Any element of an array or structure can be independently expanded or contracted; you need not display every element of the variable. If you want to view only one or two elements of a large array, specify the particular array or structure elements in the Expression field of the Add Watch dialog box.
You can dereference a pointer in the same way as an array or structure. The Watch window displays the pointer address, followed by all the elements of the variable to which the pointer currently refers. You can display multiple levels of indirection (that is, pointers referencing other pointers) simultaneously.
An array may have dynamic elements that change as some other variable changes. Just as you can display a particular element of an array by selecting its subscript, you can also display a dynamic array element by specifying its variable subscript. For example, suppose that the loop variable p is a subscript for the array variable Catalogprice. The Watch window expression Catalogprice[p] displays only the array element currently specified by the variable p, not the entire array.
You can mix constant and variable subscripts. For example, the expression BigArray[3][i] displays only the element in the third row of the array to which the index variable i points.