Type Casting Examples

This section contains some common type casting examples, as follows:

Displaying the argv Array

Typically, argv is the second argument passed to main(), and it is either a char **argv or char *argv[ ]. Since these declarations are equivalent (a pointer to one or more pointers to characters), TotalView converts both to <string>** (a pointer to one or more pointers to null-terminated strings).

Suppose argv points to an array of three pointers to character strings. Here is how you can edit its type to display an array of three pointers:

  1. Select the type string for argv.
     
  2. Edit the type string using the field editor commands. Change it to:

        <string>*[3]*
     

  3. To display the array, dive into the value field for argv.

    Editing argv

Displaying Declared Arrays

TotalView displays arrays in the same way as it displays local and global variables. In the Stack Frame or Source Pane, dive into the declared array. A Variable Window displays the elements of the array.

Displaying Allocated Arrays

The C language uses pointers for dynamically allocated arrays. For example:

int *p = malloc(sizeof(int) * 20);

Because TotalView does not know that p actually points to an array of integers, here is how you would display the array:

  1. Dive on the variable p of type int*.
     
  2. Change its type to int[20]*.
     
  3. Dive on the value of the pointer to display the array of 20 integers.
 
 
 
 
support@etnus.com
Copyright © 2001, Etnus, LLC. All rights reserved.
Version 5.0