1Tcl_ExprLong(3) Tcl Library Procedures Tcl_ExprLong(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString - evalu‐
9 ate an expression
10
12 #include <tcl.h>
13
14 int
15 Tcl_ExprLong(interp, string, longPtr)
16
17 int
18 Tcl_ExprDouble(interp, string, doublePtr)
19
20 int
21 Tcl_ExprBoolean(interp, string, booleanPtr)
22
23 int
24 Tcl_ExprString(interp, string)
25
27 Tcl_Interp *interp (in) Interpreter in whose context to
28 evaluate string. │
29
30 CONST char *string (in) │
31 Expression to be evaluated.
32
33 long *longPtr (out) Pointer to location in which to
34 store the integer value of the
35 expression.
36
37 int *doublePtr (out) Pointer to location in which to
38 store the floating-point value of
39 the expression.
40
41 int *booleanPtr (out) Pointer to location in which to
42 store the 0/1 boolean value of the
43 expression.
44_________________________________________________________________
45
46
48 These four procedures all evaluate the expression given by the string
49 argument and return the result in one of four different forms. The
50 expression can have any of the forms accepted by the expr command.
51 Note that these procedures have been largely replaced by the object-
52 based procedures Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_Expr‐
53 BooleanObj, and Tcl_ExprObj. Those object-based procedures evaluate an
54 expression held in a Tcl object instead of a string. The object argu‐
55 ment can retain an internal representation that is more efficient to
56 execute.
57
58 The interp argument refers to an interpreter used to evaluate the
59 expression (e.g. for variables and nested Tcl commands) and to return
60 error information.
61
62 For all of these procedures the return value is a standard Tcl result:
63 TCL_OK means the expression was successfully evaluated, and TCL_ERROR
64 means that an error occurred while evaluating the expression. If
65 TCL_ERROR is returned then the interpreter's result will hold a message
66 describing the error. If an error occurs while executing a Tcl command
67 embedded in the expression then that error will be returned.
68
69 If the expression is successfully evaluated, then its value is returned
70 in one of four forms, depending on which procedure is invoked.
71 Tcl_ExprLong stores an integer value at *longPtr. If the expression's
72 actual value is a floating-point number, then it is truncated to an
73 integer. If the expression's actual value is a non-numeric string then
74 an error is returned.
75
76 Tcl_ExprDouble stores a floating-point value at *doublePtr. If the
77 expression's actual value is an integer, it is converted to floating-
78 point. If the expression's actual value is a non-numeric string then
79 an error is returned.
80
81 Tcl_ExprBoolean stores a 0/1 integer value at *booleanPtr. If the
82 expression's actual value is an integer or floating-point number, then
83 they store 0 at *booleanPtr if the value was zero and 1 otherwise. If
84 the expression's actual value is a non-numeric string then it must be
85 one of the values accepted by Tcl_GetBoolean such as ``yes'' or ``no'',
86 or else an error occurs.
87
88 Tcl_ExprString returns the value of the expression as a string stored
89 in the interpreter's result.
90
91
93 Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj
94
95
97 boolean, double, evaluate, expression, integer, object, string
98
99
100
101Tcl 7.0 Tcl_ExprLong(3)