---
name: "BoolObj"
section: "3"
platform: "macos"
package: "tcl"
version: "152"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/BoolObj"
---

# BoolObj(3)

store/retrieve boolean value in a Tcl\_Obj

## NAME

Tcl\_NewBooleanObj, Tcl\_SetBooleanObj, Tcl\_GetBooleanFromObj - store/retrieve boolean value in a Tcl\_Obj

## SYNOPSIS

```
#include <tcl.h>

Tcl_Obj *
Tcl_NewBooleanObj(boolValue)

Tcl_SetBooleanObj(objPtr, boolValue)

int
Tcl_GetBooleanFromObj(interp, objPtr, boolPtr)
```

## ARGUMENTS

Integer value to be stored as a boolean value in a Tcl\_Obj. Points to the Tcl\_Obj in which to store, or from which to retrieve a boolean value. If a boolean value cannot be retrieved, an error message is left in the interpreter's result object unless *interp* is NULL. Points to place where **Tcl\_GetBooleanFromObj** stores the boolean value (0 or 1) obtained from *objPtr*.

## DESCRIPTION

These procedures are used to pass boolean values to and from Tcl as Tcl\_Obj's.  When storing a boolean value into a Tcl\_Obj, any non-zero integer value in *boolValue* is taken to be the boolean value **1**, and the integer value **0** is taken to be the boolean value **0**.

**Tcl\_NewBooleanObj** creates a new Tcl\_Obj, stores the boolean value *boolValue* in it, and returns a pointer to the new Tcl\_Obj. The new Tcl\_Obj has reference count of zero.

**Tcl\_SetBooleanObj** accepts *objPtr*, a pointer to an existing Tcl\_Obj, and stores in the Tcl\_Obj *\*objPtr*  the boolean value *boolValue*.  This is a write operation on *\*objPtr*, so *objPtr* must be unshared.  Attempts to write to a shared Tcl\_Obj will panic.  A successful write of *boolValue* into *\*objPtr* implies the freeing of any former value stored in *\*objPtr*.

**Tcl\_GetBooleanFromObj** attempts to retrieve a boolean value from the value stored in *\*objPtr*. If *objPtr* holds a string value recognized by **Tcl\_GetBoolean**, then the recognized boolean value is written at the address given by *boolPtr*.   If *objPtr* holds any value recognized as a number by Tcl, then if that value is zero a 0 is written at the address given by *boolPtr* and if that value is non-zero a 1 is written at the address given by *boolPtr*. In all cases where a value is written at the address given by *boolPtr*, **Tcl\_GetBooleanFromObj** returns **TCL\_OK**. If the value of *objPtr* does not meet any of the conditions above, then **TCL\_ERROR** is returned and an error message is  left in the interpreter's result unless *interp* is NULL. **Tcl\_GetBooleanFromObj** may also make changes to the internal fields of *\*objPtr* so that future calls to  **Tcl\_GetBooleanFromObj** on the same *objPtr* can be performed more efficiently.

Note that the routines **Tcl\_GetBooleanFromObj** and **Tcl\_GetBoolean** are not functional equivalents. The set of values for which **Tcl\_GetBooleanFromObj** will return **TCL\_OK** is strictly larger than the set of values for which **Tcl\_GetBoolean** will do the same. For example, the value passed to **Tcl\_GetBooleanFromObj** will lead to a **TCL\_OK** return (and the boolean value 1), while the same value passed to **Tcl\_GetBoolean** will lead to a **TCL\_ERROR** return.

## SEE ALSO

Tcl\_NewObj, Tcl\_IsShared, Tcl\_GetBoolean

## KEYWORDS

boolean, object
