dassign
Changes the value of a scalar variable
Format:
dassign target value
Arguments:
target
The name of a scalar variable within your program.
value
A source-language expression that evaluates to a scalar value. This expression can use the name of another variable.
Description:
The dassign command evaluates an expression and replaces the value of a variable with the evaluated result. The location may be a scalar variable, a dereferenced pointer variable, or an element in an array or structure.
The default focus for dassign is thread. So, if you do not change the focus, this command acts upon the thread of interest. If the current focus specifies a width that is wider than t (thread) and is not d (default), dassign iterates over the threads in the focus set and performs the assignment in each. In addition, if you use a list with the dfocus command, dassign iterates over each list member.
The CLI interprets each symbol name in the expression according to the current context. Because the value of a source variable may not have the same value across threads and processes, the value assigned can differ in your threads and processes. If the data type of the resulting value is incompatible with that of the target location, you must cast the value into the target's type. (Casting is described in Chapter 7 of the TotalView Users Guide.)
Here are some things you should know about assigning characters and strings:
- If you are assigning a character to a target, place the character value within single quotation marks; for example, 'c'.
- You can use the standard C language escape character sequences; for example, \n, \t, and the like. These escape sequences can also be within a character or string assignment.
- If you are assigning a string to a target, place the string within quotation marks. However, you must "escape" the quotation marks so they are not interpreted by Tcl; for example, \"The quick brown fox\".
If value contains an expression, the expression is evaluated by TotalView's expression system. This system is discussed in Chapter 8 of the TotalView Users Guide.
Command alias:
You may find the following alias useful:
Alias |
Definition |
Meaning |
as |
{dassign} |
Changes a scalar variable's value. |
Examples:
dassign scalar_y 102
Stores the value 102 in each occurrence of variable scalar_y for all processes and threads in the current set.
dassign i 10*10
Stores the value 100 in variable i.
dassign i i*i
Does not work and the CLI displays an error message. If i is a simple scalar variable, you could use the following statements:
set x [lindex [capture dprint i] 2]
dassign i [expr $x * $x]
f {p1 p2 p3} as scalar_y 102
Stores the value 102 in each occurrence of variable scalar_y contained within processes 1, 2, and 3.