Tcl_ExprLong(3)
β¨ NAME β¨
Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString β bestie, these four literally evaluate an expression for you π
This is the Tcl Library Procedures page, i.e. Tcl_ExprLong(3), so if you're writing C and you need to crunch a Tcl expression into a number, a float, a boolean, or a string, you're in exactly the right place. π
π¦ SYNOPSIS π¦
#include <tcl.h>
int
Tcl_ExprLong(interp, expr, longPtr)
int
Tcl_ExprDouble(interp, expr, doublePtr)
int
Tcl_ExprBoolean(interp, expr, booleanPtr)
int
Tcl_ExprString(interp, expr)
πΈ ARGUMENTS πΈ
Tcl_Interp *interp (in)β the interpreter in whose context you're evaluatingexpr. Think of it as the little universe where your expression gets to exist and pop off. β¨const char *expr (in)β the actual expression being evaluated. This is the main character right here. πlong *longPtr (out)β pointer to the spot where the integer value of the expression gets stored. It's an out param, so it's holding your results, not your opinions. πint *doublePtr (out)β pointer to the spot where the floating-point value of the expression gets stored. Yes, it's declaredint *in the synopsis and that's literally how the page prints it, so we're keeping it exactly like that, no cap. πint *booleanPtr (out)β pointer to the spot where the0/1boolean value of the expression gets stored. Zero or one, that's it, that's the whole vibe. π
π DESCRIPTION π
okay so, all four of these procedures do the same iconic thing: they evaluate the expression handed to them in the expr argument, and then they hand the result back to you in one of four different forms. Pick your fighter. π«Ά
The expression can have any of the forms accepted by the expr command. Fr fr, anything expr can chew on.
but bestie, real talk: these procedures have been largely replaced by the value-based proceduresTcl_ExprLongObj,Tcl_ExprDoubleObj,Tcl_ExprBooleanObj, andTcl_ExprObj. Those value-based ones evaluate an expression held in a Tcl value instead of a string, and the value argument can retain an internal representation that is more efficient to execute. So likeβ¦ slay, but the Obj versions ate. π
The interp argument refers to an interpreter used to evaluate the expression (e.g. for variables and nested Tcl commands) and to return error information.
For all of these procedures the return value is a standard Tcl result: TCL_OK means the expression was successfully evaluated, and TCL_ERROR means that an error occurred while evaluating the expression. If TCL_ERROR is returned then the interpreter's result will hold a message describing the error. And if an error occurs while executing a Tcl command embedded in the expression, then that error will be returned. No cover-ups, we report what happened. π
If the expression is successfully evaluated, then its value is returned in one of four forms, depending on which procedure is invoked:
Tcl_ExprLongβ stores an integer value at*longPtr. If the expression's actual value is a floating-point number, then it is truncated to an integer (just chopped, don't cry about it). If the expression's actual value is a non-numeric string then an error is returned. πTcl_ExprDoubleβ stores a floating-point value at*doublePtr. If the expression's actual value is an integer, it is converted to floating-point. If the expression's actual value is a non-numeric string then an error is returned. β¨Tcl_ExprBooleanβ stores a0/1integer value at*booleanPtr. If the expression's actual value is an integer or floating-point number, then they store0at*booleanPtrif the value was zero and1otherwise. If the expression's actual value is a non-numeric string then it must be one of the values accepted byTcl_GetBooleansuch asyesorno, or else an error occurs. π§Tcl_ExprStringβ returns the value of the expression as a string stored in the interpreter's result. The string one, the chill one, the low-effort-but-still-valid one. π
π SEE ALSO π
Tcl_ExprLongObjTcl_ExprDoubleObjTcl_ExprBooleanObjTcl_ExprObj
(the glow-up squad, go check them out π)
β KEYWORDS β
boolean, double, evaluate, expression, integer, value, string
and that's the whole page bestie!! π this lil legend is from Tcl, version 7.0, page Tcl_ExprLong(3) β go forth and evaluate responsibly, mwah ππ¦
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1989-1993 The Regents of the University of California
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms