30.01.2013 Views

TotalView Users Guide - CI Wiki

TotalView Users Guide - CI Wiki

TotalView Users Guide - CI Wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Why is There an Expression System?<br />

Figure 238: Expression List<br />

Window: Accessing Array<br />

Elements<br />

Looking up array data is slightly more complicated. For example, if the program<br />

wants my_var[9]—this chapter will most often use C and C++ notation<br />

rather than Fortran—it looks up the array’s starting address, then<br />

applies an offset to locate the array’s 10 element. In this case, if each array<br />

element uses 32 bits, my_var[9] is located 9 times 32 bits away.<br />

In a similar fashion, your program obtains information about variables<br />

stored in structures and arrays of structures.<br />

Structures complicate matters slightly. For example ptr->my_var requires<br />

three operations: extract the data contained within address of the my_var<br />

variable, use this information to access the data at the address being<br />

pointed to, then display the data according to the variable’s datatype.<br />

Accessing an array element such as my_var[9] where the array index is an<br />

integer constant is rare in most programs. In most cases, your program<br />

uses variables or expressions as array indices; for example, my_var[cntr] or<br />

my_var[cntr+3]. In the later case, <strong>TotalView</strong> must determine the value of<br />

cntr+3 before it can access an array element.<br />

Using variables and expressions as array indices are common. However, the<br />

array index can be (and often is) an integer returned by a function. For<br />

example:<br />

my_var[access_func(first_var, second_var)+2]<br />

In this example, a function with two arguments returns a value. That<br />

returned value is incremented by two, and the resulting value becomes the<br />

array index. Here is an illustration showing <strong>TotalView</strong> accessing the my_var<br />

array in the four ways discussed in this section:<br />

In Fortran and C, access to data is usually through variables with some sort<br />

of simple evaluation or a function. Access to variable information can be<br />

the same in C++ as it is in these languages. However, accessing private<br />

variables within a class almost always uses a method. For example:<br />

myDataStructureList.get_current_place()<br />

<strong>TotalView</strong> built-in expression evaluation system is able to understand your<br />

class inheritance structure in addition to following C++ rules for method<br />

382 Chapter 17: Evaluating Expressions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!