Tcl Library Procedures


Tcl_NewIntObj, Tcl_SetIntObj, Tcl_GetIntFromObj - manipulate integer Tcl objects


#include <tcl.h>

Tcl_Obj *

Tcl_SetIntObj(objPtr, intValue)

Tcl_GetIntFromObj(interp, objPtr, intPtr)


long intValue (in)
Integer value used to initialize or set an integer object.

Tcl_Obj *objPtr (in/out)
For Tcl_SetIntObj, this points to the object to be converted to integer type. For Tcl_GetIntFromObj, this refers to the object from which to get an integer value; if objPtr does not already point to an integer object, an attempt will be made to convert it to one.

Tcl_Interp *interp (in/out)
If an error occurs during conversion, an error message is left in interp->objResult unless interp is NULL.

long *intPtr (out)
Points to place to store the integer value obtained from objPtr.


These procedures are used to create, modify, and read integer Tcl objects from C code. Tcl_NewIntObj and Tcl_SetIntObj will create a new object of integer type or modify an existing object to have integer type. Both of these procedures set the object to have the integer value given by intValue; Tcl_NewIntObj returns a pointer to a newly created object with reference count 1. Both procedures set the object's type to be integer (i.e., they store the address of the integer Tcl_ObjType structure in the object's typePtr member) and assign the integer value to the object's internal representation intValue member. Tcl_SetIntObj invalidates any old string representation and, if the object is not already an integer object, frees any old internal representation.

Tcl_GetIntFromObj attempts to return an integer value from the Tcl object objPtr. If the object is not already an integer object, it will attempt to convert it to one. If an error occurs during conversion, it returns TCL_ERROR and leaves an error message in interp->objResult unless interp is NULL. This message object can be retrieved using Tcl_GetObjResult. Otherwise, it returns TCL_OK and stores the integer value in the address given by intPtr. If the object is not already an integer object, the conversion will free any old internal representation.


Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult


integer, integer object, integer type, internal representation, object, object type, string representation

Last change: 8.0

[ tcl8.0a1 | tk8.0a1 | X-ref ]

Copyright © 1989-1994 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.