Tcl_ExprLongObj(3tcl)
π Tcl_ExprLongObj β the "evaluate an expression" besties π
ok so this is the Tcl Library Procedures page for Tcl_ExprLongObj and its three girlies, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, and Tcl_ExprObj. four functions, one job: evaluate an expression β¨
β¨ NAME β¨
Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj β evaluate an expression π§
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_ExprLongObj(interp, objPtr, longPtr)
int
Tcl_ExprDoubleObj(interp, objPtr, doublePtr)
int
Tcl_ExprBooleanObj(interp, objPtr, booleanPtr)
int
Tcl_ExprObj(interp, objPtr, resultPtrPtr)
π ARGUMENTS π
Tcl_Interp *interp(in) β the interpreter in whose context we evaluateobjPtr. she's the whole vibe, she holds the variables and the nested commands and the drama (errors).Tcl_Obj *objPtr(in) β pointer to a value holding the expression we're about to evaluate. yes bestie, the expression lives inside aTcl_Obj.long *longPtr(out) β pointer to the spot where the integer value of the expression goes.int *doublePtr(out) β pointer to the spot where the floating-point value of the expression goes. (yes, the manpage literally types itint *here, we don't question the ancestors π)int *booleanPtr(out) β pointer to the spot where the 0/1 boolean value of the expression goes.Tcl_Obj **resultPtrPtr(out) β pointer to the spot where we stash a pointer to the value that is the result of the expression. pointer-to-a-pointer, iconic behavior, she contains multitudes π
π DESCRIPTION π
okay so all four of these procedures evaluate an expression, and they just hand the answer back in four different forms. the expression comes in through the objPtr argument, and it can take any of the forms that the expr command accepts. anything expr can do, these can do. no cap.
the interp argument is the interpreter used to evaluate the expression β she's the one with the variables, the nested Tcl commands, all of it β and she's also the one who returns error info when things go sideways.
for all of these procedures the return value is a standard Tcl result:
TCL_OKmeans the expression was successfully evaluated πTCL_ERRORmeans an error happened while evaluating the expression π
if TCL_ERROR comes back, then you can grab a message describing the error using Tcl_GetObjResult. and lowkey important: if an error happens while executing a Tcl command that's embedded inside the expression, then that error is what gets returned. it propagates, periodt.
if the expression evaluates fine, then its value comes back in one of four forms, depending on which procedure you called:
Tcl_ExprLongObjstores an integer value at*longPtr. if the expression's actual value is a floating-point number, it gets truncated to an integer (yes, chopped, no rounding romance). and if the expression's actual value is a non-numeric string, you get an error. sorry bestie.Tcl_ExprDoubleObjstores a floating-point value at*doublePtr. if the expression's actual value is an integer, it gets converted to floating-point. if it's a non-numeric string, error again, no exceptions.Tcl_ExprBooleanObjstores a 0/1 integer value at*booleanPtr. if the expression's actual value is an integer or a floating-point number, then it stores0at*booleanPtrif the value was zero, and1otherwise. if the expression's actual value is a non-numeric string, then it has to be one of the values accepted byTcl_GetBooleanβ things like βyesβ or βnoβ β or else an error occurs.Tcl_ExprObj, if it successfully evaluates the expression, stores a pointer to theTclvalue containing the expression's value at*resultPtrPtr. and this is the part where you have to be a responsible main character: the caller is responsible for callingTcl_DecrRefCountto decrement the value's reference count once they're done with the value. do not forget her. she will leak. π
π¦ REFERENCE COUNT MANAGEMENT π¦
Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, and Tcl_ExprObj all increment and decrement the reference count of their objPtr arguments.
so listen: you must not pass them any value with a reference count of zero. that's a hard no.
they also manipulate the interpreter result β which means you must not count on the interpreter result to hold the reference count of any value across these calls. don't do it. she's not holding it for you. π
π SEE ALSO π
Tcl_ExprLongTcl_ExprDoubleTcl_ExprBooleanTcl_ExprStringTcl_GetObjResult
π KEYWORDS π
boolean, double, evaluate, expression, integer, value, string
and that's the whole page bestie, go evaluate something iconic πβ¨
this was Tcl_ExprLongObj(3tcl), living in the Tcl library procedures, version 8.0 β mwah, stan forever π«ΆπΈ
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1996-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms