Tcl_IntObj(3)
๐ Tcl_IntObj(3) โ Tcl Library Procedures ๐
okay bestie, sit down, hydrate, because today we're learning how Tcl stores numbers. This is Tcl_IntObj from the Tcl Library Procedures manual, and it's literally the whole girl-math pipeline: making ints, setting ints, getting ints back out. No cap. ๐งฎโจ
๐ธ NAME ๐ธ
Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_NewWideUIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_SetWideUIntObj, Tcl_GetIntFromObj, Tcl_GetIntForIndex, Tcl_GetLongFromObj, Tcl_GetSizeIntFromObj, Tcl_GetWideIntFromObj, Tcl_GetWideUIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj โ manipulate Tcl values as integers. that's the whole vibe. ๐
โจ SYNOPSIS โจ
#include <tcl.h>
Tcl_Obj *
Tcl_NewIntObj(intValue)
Tcl_Obj *
Tcl_NewLongObj(longValue)
Tcl_Obj *
Tcl_NewWideIntObj(wideValue)
Tcl_Obj *
Tcl_NewWideUIntObj(uwideValue)
Tcl_SetIntObj(objPtr, intValue)
Tcl_SetLongObj(objPtr, longValue)
Tcl_SetWideIntObj(objPtr, wideValue)
Tcl_SetWideUIntObj(objPtr, uwideValue)
int
Tcl_GetIntFromObj(interp, objPtr, intPtr)
int
Tcl_GetIntForIndex(interp, objPtr, endValue, indexPtr)
int
Tcl_GetLongFromObj(interp, objPtr, longPtr)
int
Tcl_GetWideIntFromObj(interp, objPtr, widePtr)
int
Tcl_GetWideUIntFromObj(interp, objPtr, uwidePtr)
int
Tcl_GetSizeIntFromObj(interp, objPtr, sizePtr)
#include <tclTomMath.h>
Tcl_Obj *
Tcl_NewBignumObj(bigValue)
Tcl_SetBignumObj(objPtr, bigValue)
int
Tcl_GetBignumFromObj(interp, objPtr, bigValue)
int
Tcl_TakeBignumFromObj(interp, objPtr, bigValue)
int
Tcl_InitBignumFromDouble(interp, doubleValue, bigValue)
๐ ARGUMENTS ๐
Tcl_Size endValue(in) โ the valueTcl_GetIntForIndexhands back when the input value is"end". it's giving "the end is a real place and it has a number". ๐ฆint intValue(in) โ an integer value, used to initialize or set a Tcl value.long longValue(in) โ a long integer value, used to initialize or set a Tcl value.Tcl_WideInt wideValue(in) โ a wide integer value, used to initialize or set a Tcl value.Tcl_WideUInt uwideValue(in) โ an unsigned wide integer value, used to initialize or set a Tcl value.Tcl_Obj *objPtr(in/out) โ forTcl_SetIntObj,Tcl_SetLongObj,Tcl_SetWideIntObj,Tcl_SetWideUIntObj, andTcl_SetBignumObj, this points to the value where you're storing an integral value. forTcl_GetIntFromObj,Tcl_GetLongFromObj,Tcl_GetWideIntFromObj,Tcl_GetBignumFromObj, andTcl_TakeBignumFromObj, it refers to the value you're pulling an integral value out of. same pointer, two moods. ๐Tcl_Interp *interp(in/out) โ when it's non-NULL, an error message gets dropped here if integral value retrieval fails. your little error inbox. ๐ฅint *intPtr(out) โ points to the place to store the integer value retrieved fromobjPtr.long *longPtr(out) โ points to the place to store the long integer value retrieved fromobjPtr.Tcl_Size *indexPtr(out) โ points to the place to store theTcl_Sizevalue retrieved fromobjPtr.Tcl_WideInt *widePtr(out) โ points to the place to store the wide integer value retrieved fromobjPtr.Tcl_WideUInt *uwidePtr(out) โ points to the place to store the unsigned wide integer value retrieved fromobjPtr.Tcl_Size *sizePtr(out) โ points to the place to store theTcl_Sizeinteger value retrieved fromobjPtr.mp_int *bigValue(in/out) โ points to a multi-precision integer structure declared by the LibTomMath library. big number energy, literally. ๐ฅdouble doubleValue(in) โ a double value; the integer part gets determined from it and used to initialize a multi-precision integer value.
๐ DESCRIPTION ๐
these procedures create, modify, and read Tcl values that hold integral values. that's the whole job. ๐ซถ
the different routines exist to accommodate different integral types in C, because values might get exchanged with any of them. the C integral types Tcl provides value exchange routines for are int, long int, Tcl_WideInt, and mp_int. the int and long int types are provided by the C language standard. the Tcl_WideInt type is a typedef defined to be whatever signed integral type covers at least the 64-bit integer range (-9223372036854775808 to 9223372036854775807). depending on the platform and the C compiler, the actual type might be long long int, or something else. the Tcl_Size typedef is a signed integer type capable of holding the maximum permitted lengths of Tcl values like strings and lists. and correspondingly, the preprocessor constant TCL_SIZE_MAX defines the maximum value that can be stored in a variable of this type. the mp_int type is a multiple-precision integer type defined by the LibTomMath multiple-precision integer library. ๐
the Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_NewWideUIntObj, and Tcl_NewBignumObj routines each create and return a brand-new Tcl value initialized to the integral value of the argument. the returned Tcl value is unshared. it's fresh out the box, nobody else is holding it. โจ
the Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_SetWideUIntObj, and Tcl_SetBignumObj routines each set the value of an existing Tcl value pointed to by objPtr to the integral value provided by the other argument. the objPtr argument must point to an unshared Tcl value. any attempt to set the value of a shared Tcl value violates Tcl's copy-on-write policy. ๐ญ and any existing string representation or internal representation in the unshared Tcl value will be freed as a consequence of setting the new value. gone. freed. bye. ๐ฆ
the Tcl_GetIntForIndex routine attempts to retrieve an index value from the Tcl value objPtr. if the attempt succeeds, then TCL_OK is returned, and the value is written to the storage provided by the caller. the attempt might fail if objPtr does not hold an index value. if the attempt fails, then TCL_ERROR is returned, and if interp is non-NULL, an error message is left in interp. the Tcl_ObjType of objPtr may be changed to make subsequent calls to the same routine more efficient. glow-up for later calls. ๐
the Tcl_GetIntFromObj, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_GetSizeIntFromObj, Tcl_GetBignumFromObj, and Tcl_TakeBignumFromObj routines attempt to retrieve an integral value of the appropriate type from the Tcl value objPtr. if the attempt succeeds, then TCL_OK is returned, and the value is written to the storage provided by the caller. the attempt might fail if objPtr does not hold an integral value, or if the value exceeds the range of the target type. if the attempt fails, then TCL_ERROR is returned, and if interp is non-NULL, an error message is left in interp. the Tcl_ObjType of objPtr may be changed to make subsequent calls to the same routine more efficient. and unlike the other functions, Tcl_TakeBignumFromObj may set the content of the Tcl value objPtr to an empty string in the process of retrieving the multiple-precision integer value. yeah she empties the bag while she shops. ๐๏ธ
the choice between Tcl_GetBignumFromObj and Tcl_TakeBignumFromObj is governed by how the caller will continue to use objPtr. if, after the mp_int value is retrieved from objPtr, the caller will make no more use of objPtr, then using Tcl_TakeBignumFromObj permits Tcl to detect when an unshared objPtr permits the value to be moved instead of copied, which should be more efficient. if anything later in the caller requires objPtr to continue to hold the same value, then Tcl_GetBignumFromObj must be chosen. no take-backs, bestie. choose wisely. ๐
the Tcl_InitBignumFromDouble routine is a utility procedure that extracts the integer part of doubleValue and stores that integer value in the mp_int value bigValue. cute lil helper. ๐
๐ REFERENCE COUNT MANAGEMENT ๐
Tcl_NewIntObj,Tcl_NewLongObj,Tcl_NewWideIntObj, andTcl_NewBignumObjalways return a zero-reference object, much likeTcl_NewObj. brand new, refcount zero, all yours. โญTcl_SetIntObj,Tcl_SetLongObj,Tcl_SetWideIntObj, andTcl_SetBignumObjdo not modify the reference count of theirobjPtrarguments, but they do require that the object be unshared. ๐Tcl_GetIntFromObj,Tcl_GetIntForIndex,Tcl_GetLongFromObj,Tcl_GetWideIntFromObj,Tcl_GetSizeIntFromObj,Tcl_GetBignumFromObj, andTcl_TakeBignumFromObjdo not modify the reference count of theirobjPtrarguments; they only read. note however that this function may set the interpreter result; if that is the only place that is holding a reference to the object, it will be deleted. ๐ also note that ifTcl_TakeBignumFromObjis given an unshared value, the value of that object may be modified; it is intended to be used when the value is โconsumedโ by the operation at this point.
๐ SEE ALSO ๐
Tcl_NewObjTcl_DecrRefCountTcl_IncrRefCountTcl_GetObjResult
๐ฅ KEYWORDS ๐ฅ
integer, integer value, integer type, internal representation, value, value type, string representation
okay that's the whole page, you ate it, periodt. ๐
โจ this lil masterpiece is from the Tcl manual, version 8.5, filed under Tcl_IntObj(3) โ go forth and manipulate some integers, bestie, you've got this. ๐ซถ๐๐ฆ
๐ฆ 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) 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