Bewerken

Delen via


Evaluating Expressions

The debugger understands two different forms of expressions: MASM expressions and C++ expressions.

Microsoft Macro Assembler (MASM) expressions are used in the examples in this Help documentation, except when otherwise noted. In MASM expressions, all symbols are treated as addresses.

C++ expressions are the same as those used in actual C++ code. In these expressions, symbols are understood as the appropriate data types.

When Each Syntax is Used

You can select the default expression evaluator in one of the following ways:

If you do not use one of the preceding methods, the debugger uses the MASM expression evaluator.

If you want to evaluate an expression without changing the debugger state, you can use the ? (Evaluate Expression) command.

All commands and debugging information windows interpret their arguments through the default expression evaluator, with the following exceptions:

  • The ?? (Evaluate C++ Expression) command always uses the C++ expression evaluator.

  • The Watch window always uses the C++ expression evaluator.

  • The Locals window always uses the C++ expression evaluator.

  • Some extension commands always use the MASM expression evaluator (and other extension commands accept only numeric arguments instead of full expressions).

  • If any part of an expression is enclosed in parentheses and you insert two at signs (@@) before the expression, the expression is evaluated by the expression evaluator that would not typically be used in this case.

The two at signs (@@) enable you to use two different evaluators for different parameters of a single command. It also enables you to evaluate different pieces of a long expression by different methods. You can nest the two at signs. Each appearance of the two at signs switches to the other expression evaluator.

Warning   C++ expression syntax is useful for manipulating structures and variables, but it is not well-suited as a parser for the parameters of debugger commands. When you are using debugger commands for general purposes or you are using debugger extensions, you should set MASM expression syntax as the default expression evaluator. If you must have a specific parameter use C++ expression syntax, use the two at sign (@@) syntax.

For more information about the two different expression types, see Numerical Expression Syntax.

Numbers in Expressions

Numbers in MASM expressions are interpreted according to the current radix. The n (Set Number Base) command can be used to set the default radix to 16, 10, or 8. All un-prefixed numbers will be interpreted in this base. The default radix can be overridden by specifying the 0x prefix (hexadecimal), the 0n prefix (decimal), the 0t prefix (octal), or the 0y prefix (binary).

Numbers in C++ expressions are interpreted as decimal numbers unless you specify differently. To specify a hexadecimal integer, add 0x before the number. To specify an octal integer, add 0 (zero) before the number. (However, in the debugger's output, the 0n decimal prefix is sometimes used.)

If you want to display a number in several bases at the same time, use the .formats (Show Number Formats) command.

Symbols in Expressions

The two types of expressions interpret symbols differently:

  • In MASM expressions, each symbol is interpreted as an address. Depending on what the symbol refers to, this address is the address of a global variable, local variable, function, segment, module, or any other recognized label.

  • In C++ expressions, each symbol is interpreted according to its type. Depending on what the symbol refers to, it might be interpreted as an integer, a data structure, a function pointer, or any other data type. A symbol that does not correspond to a C++ data type (such as an unmodified module name) creates a syntax error.

If a symbol might be ambiguous, precede it with the module name and an exclamation point ( ! ). If the symbol name could be interpreted as a hexadecimal number, precede it with the module name and an exclamation point ( ! ) or only an exclamation point. In order to specify that a symbol is meant to be local, omit the module name, and include a dollar sign and an exclamation point ( $! ) before the symbol name. For more information about interpreting symbols, see Symbol Syntax and Symbol Matching.

Operators in Expressions

Each expression type uses a different collection of operators.

For more information about the operators that you can use in MASM expressions and their precedence rules, see MASM Numbers and Operators.

For more information about the operators that you can use in C++ expressions and their precedence rules, see C++ Numbers and Operators.

Remember that MASM operations are always byte-based, and C++ operations follow C++ type rules (including the scaling of pointer arithmetic).

For some examples of the different syntaxes, see Mixed Expression Examples.