Share via


Restrictions on Native C++ Expressions 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Express

No

No

Native

No

Standard

No

No

Native

No

Pro/Team

No

No

Native

No

When you enter a C/C++ expression in a debugger window, these general restrictions apply:

Access Control

The debugger can access all class members regardless of access control. You can examine any class object member, including base classes and embedded member objects.

Ambiguous References

If a debugger expression refers to an ambiguous member name, you must use the class name to qualify it. For example, if CObject is an instance of CClass, which inherits member functions named expense from both AClass and BClass, CObject.expense is ambiguous. You can resolve the ambiguity like this:

CObject.BClass::expense

To resolve ambiguities, the expression evaluator applies normal dominance rules regarding member names.

Anonymous Namespaces

The native C++ expression evaluator does not support anonymous namespaces. Suppose, for example, you have the following code:

#include "stdafx.h"

namespace mars

{

namespace

{

int test = 0;

}

}

int main()

{

// Adding a watch on test does not work.

mars::test++;

return 0;

}

The only way to watch the symbol test in this example is to use the decorated name:

(int*)?test@?A0xccd06570@mars@@3HA

Constructors, Destructors, and Conversions

You cannot call a constructor or destructor for an object, either explicitly or implicitly, using an expression that calls for construction of a temporary object. For example, the following expression explicitly calls a constructor and results in an error message:

Date( 2, 3, 1985 )

You cannot call a conversion function if the destination of the conversion is a class. Such a conversion involves the construction of an object. For example, if myFraction is an instance of CFraction, which defines the conversion function operator FixedPoint, the following expression results in an error:

(FixedPoint)myFraction

However, you can call a conversion function if the destination of the conversion is a built-in type. If CFraction defines a conversion function operator float, the following expression is legal in the debugger:

(float)myFraction

You can call functions that return an object or declare local objects.

You cannot call the new or delete operators. The following expression does not work in the debugger:

new Date(2,3,1985)

Inheritance

When you use the debugger to display a class object that has virtual base classes, the members of the virtual base class are displayed for each inheritance path, even though only one instance of those members is stored.

Virtual function calls are properly handled by the expression evaluator. For example, assume the class CEmployee defines a virtual function computePay, which is redefined in a class that inherits from CEmployee. You can call computePay through a pointer to CEmployee and have the proper function executed:

empPtr->computePay()

You can cast a pointer to a derived class object into a pointer to a base class object. The reverse cast is not permitted.

Intrinsic and Inlined Functions

A debugger expression cannot call an intrinsic or inlined function unless the function appears at least once as a normal function.

Numeric Constants

Debugger expressions can use integer constants in octal, hexadecimal, or decimal format. By default, the debugger expects decimal constants. This setting can be changed on the General page of the Debugging tab.

You can use prefix or suffix symbols to represent numbers in another base. The following table shows the forms you can use.

Syntax Example (decimal 100) Base

digits

100 or 64

Decimal or hexadecimal, depending on the current setting.

0digits

0144

Octal (base 8)

0ndigits

0n100

Decimal (base 10)

0xdigits

0x64

Hexadecimal (base 16)

digitsh

64h

Hexadecimal (base 16)

Operator Functions

A debugger expression can invoke operator functions for a class implicitly or explicitly. For example, suppose myFraction and yourFraction are instances of a class that defines operator+. You can display the sum of those two objects using this expression:

myFraction + yourFraction

If an operator function is defined as a friend, you can call it implicitly using the same syntax as for a member function, or you can invoke it explicitly, as follows:

operator+( myFraction, yourFraction )

Like ordinary functions, operator functions cannot be called with arguments that require a conversion involving object construction.

The debugger does not support overloaded operators with both const and non-const versions. Overloaded operators with const and non-const versions are used frequently in the Standard Template Library.

Overloading

A debugger expression can call overloaded functions if an exact match exists or if a match does not require a conversion involving object construction. For example, if the calc function takes a CFraction object as a parameter, and the CFraction class defines a single-argument constructor that accepts an integer, the following expression results in an error:

calc( 23 )

Even though a legal conversion exists to convert the integer into the CFraction object that calc expects, such a conversion involves the creation of an object and is not supported.

Precedence

In debugger expressions, the C++ scope operator (::) has lower precedence than it does in source code. In C++ source code, this operator has the highest precedence. In the debugger, its precedence falls between the base and postfix operators (->, ++, --) and the unary operators (!, &, *, and others).

Symbol Formats

You enter a debugger expression that contains symbols in the same form used in the source code, provided the symbols are in a module compiled with full debug information (/Zi or /ZI). If you enter an expression that contains public symbols, which are symbols found in libraries or in modules compiled with /Zd, you must use the decorated name of the symbol, the form used in the object code. For more information, see /Z7, /Zd, /Zi, /ZI (Debug Information Format).

You can get a listing of all names in their decorated and undecorated forms using the LINK /MAP option. For more information, see /MAP (Generate Mapfile).

Name decoration is the mechanism used to enforce type-safe linkage. This means that only the names and references with precisely matching spelling, case, calling convention, and type are linked together.

Names declared with the C calling convention, either implicitly or explicitly using the _cdecl keyword, begin with an underscore ( _ ). For example, the function main can be displayed as _main. Names declared as _fastcall begin with the @ symbol.

For C++, the decorated name encodes the type of the symbol in addition to the calling convention. This form of the name can be long and difficult to read. The name begins with at least one question mark (?). For C++ functions, the decoration includes the function scope, the types of the function parameters, and the function return type.

Type Casting

If you cast to a type, the type must be known to the debugger. You must have another object of that type in your program. Types created using typedef statements are not supported.

See Also

Other Resources

Native C++ Language Expressions