3.8.5. Evaluating expressions

The Evaluate Expression window allows you to enter a simple C++ expression to be evaluated. The Evaluate Expression window provides similar functionality to the debugger Expression window, with a C++ interpretation of the data being displayed.

Evaluating expressions and adding watches

Follow these steps to enter an expression to be evaluated:

  1. Select Evaluate Expressions from the C++ menu or click on the Evaluate Expression button in the toolbar. The Evaluate Expression window is displayed (Figure 3.29).

    Figure 3.29. The Evaluate Expression window

    The Evaluate Expression window
  2. Enter the expression to be evaluated and press the Enter key, or click on the Calculate button. The value of the expression is displayed:

    • If the expression is a variable, the value of the variable is displayed.

    • If the expression is a logical expression, the window displays ‘1’ if the expression evaluates to true, or ‘0’ if the expression evaluates to false.

    • If the expression is a function, the value of the function is displayed. Member functions of C++ classes cannot be evaluated.

    Refer to Expression evaluation guidelines for more information on expression evaluation in C++.

  3. Click on the Add Watch button to add the expression to the Watch window.

Expression evaluation guidelines

Note

The following guidelines apply to all areas of ADW or ADU where an expression can be used, including setting watchpoints and breakpoints, and evaluating expressions in the Watch window.

The following rules apply to expression evaluation for C++ :

  • Member functions of C++ classes cannot be used in expressions.

  • Overloaded functions cannot be used in expressions.

  • Only C operators can be used in constructing expressions. Any operators defined in a C++ class that also have a meaning in C (such as []) will not work correctly because ADW and AU use the C operator instead. Specific C++ operators, such as the scope operator ::, are not recognized.

  • Member variables of a class cannot be accessed from the Evaluate Expression window in a C++ manner, as if they were local variables. To use a member variable in an expression you must use one of:

    • this->member

    • this[0].member

    • *this.member

    If the member variable is defined in a base class then this->member will return the correct results.

    In the Expression Evaluation window (and only there) you can access variables of a class by name. This means that member gives the same result as this->member. However, if you have more complex expressions such as:

    this->member1 * this->member2
    

    you cannot use:

    member1 * member2
    
  • Base classes cannot be accessed in standard C++ notation. For example:

    class Base
    {
    	char *name;
    	char *A;
    };
    class Derived : public class Base
    {
    	char *name;
    	char *B;
    	void do_sth();
    };
    

    If you are in method do_sth() you can access the member variables A, name, and B through the this pointer. For example, this->name returns the name defined in class Derived.

    To access name in class Base, the standard C++ notation is:

    void Derived::do_sth()
    {
    	Base::name="value"; // sets name in the base class 
    						// to "value"
    }
    

    However, the expression evaluation window does not accept this->Base::name because ADW and ADU do not understand the scope operator. You can access this value with:

    this->::Base.name
    
  • Though it is possible to call member functions in the form Class::Member(...), this will give undefined results.

  • private, public, and protected attributes are not recognized by the ADW or ADU Evaluate Expression window. This means that private and protected member variables can be accessed in the Evaluate Expression window because ADW and ADU treat them as public.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D
Non-Confidential