(ddd.info)Array Slices


Next: Repeated Values Up: Arrays
Enter node , (file) or (file)node

7.3.2.1 Array Slices
....................

It is often useful to print out several successive objects of the same
type in memory; a "slice" (section) of an array, or an array of
dynamically determined size for which only a pointer exists in the
program.

   Using DDD, you can display slices using the `FROM..TO' notation
(Note: Creating Multiple Displays).  But this requires that you
already know FROM and TO; it is also inefficient to create several
single displays.  If you use GDB, you have yet another alternative.

   Using GDB, you can display successive objects by referring to a
contiguous span of memory as an "artificial array", using the binary
operator `@'.  The left operand of `@' should be the first element of
the desired array and be an individual object.  The right operand
should be the desired length of the array.  The result is an array
value whose elements are all of the type of the left argument.  The
first element is actually the left argument; the second element comes
from bytes of memory immediately following those that hold the first
element, and so on.

   Here is an example.  If a program says

     int *array = (int *) malloc (len * sizeof (int));

you can print the contents of `array' with

     print array[0]@len

and display the contents with

     graph display array[0]@len

   The general form of displaying an array slice is thus

     graph display ARRAY[FIRST]@NELEMS

where ARRAY is the name of the array to display, FIRST is the index of
the first element, and NELEMS is the number of elements to display.

   The left operand of `@' must reside in memory.  Array values made
with `@' in this way behave just like other arrays in terms of
subscripting, and are coerced to pointers when used in expressions.


automatically generated by info2www version 1.2.2.9