Tcl_GetInt(3tcl)
๐ NAME ๐
Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean โ bestie, these three are the glow-up queens that convert a string into an integer, a double, or a boolean. That's it. That's the job. โจ
This whole page lives in the Tcl Library Procedures manual, and yes we're talking about Tcl_GetInt(3tcl) today. ๐ซถ
๐ SYNOPSIS ๐
#include <tcl.h>
int
Tcl_GetInt(interp, src, intPtr)
int
Tcl_GetDouble(interp, src, doublePtr)
int
Tcl_GetBoolean(interp, src, intPtr)
int
Tcl_GetBool(interp, src, flags, charPtr)
๐ธ ARGUMENTS ๐ธ
Tcl_Interp *interp(in) โ the interpreter we blame when something goes wrong. She's the one who catches the error message. ๐const char *src(in) โ the actual text value you want converted. The raw material, the main character. ๐ฆint *intPtr(out) โ a lil pointer to the spot where the integer converted from src gets stored. โจdouble *doublePtr(out) โ pointer to where the double-precision floating-point value converted from src goes. So fancy. ๐char *charPtr(out) โ pointer to where the boolean value (0or1) converted from src gets parked. ๐int flags(in) โ either0orTCL_NULL_OK. If you useTCL_NULL_OK, then the empty string orNULLwill makeTcl_GetBoolreturnTCL_OK, with*charPtrfilled with the value'\xFF'. Not a typo, not a vibe, that's literally the spec. ๐ญ
๐ DESCRIPTION ๐
Okay so here's the tea. โ These procedures convert strings into integers, or double-precision floating-point values, or booleans (which get represented as 0- or 1-valued integers). Each one takes a src argument, converts it into the internal form of one particular type, and stores the converted value at the location that the procedure's third argument is pointing at. If everything goes smoothly โ and we love that for us โ each procedure returns TCL_OK. ๐
But if src doesn't have the proper syntax for the type you asked for? Then TCL_ERROR comes back, an error message gets left in the interpreter's result, and nothing gets stored at *intPtr or *doublePtr. Empty-handed. Devastating. ๐
๐งฎ Tcl_GetInt
Tcl_GetInt expects src to be a collection of integer digits, optionally signed, and optionally preceded and followed by white space. Now here's the base-detective part, so stay with me bestie:
- If the first two characters of src, after the optional white space and sign, are
0x, then src is expected to be in hexadecimal form. ๐ฅ - Otherwise, if the first such characters are
0d, then src is expected to be in decimal form. - Otherwise, if the first such characters are
0o, then src is expected to be in octal form. - Otherwise, if the first such characters are
0b, then src is expected to be in binary form. - Otherwise, src is expected to be in decimal form. The default. The safe choice. The vanilla of number bases. ๐ฆ
๐ Tcl_GetDouble
Tcl_GetDouble expects src to be a floating-point number, and a floating-point number is, in order:
- white space
- a sign
- a sequence of digits
- a decimal point
"." - a sequence of digits
- the letter
"e" - a signed decimal exponent
- and more white space
Any of those fields may be omitted โ EXCEPT the digits either before or after the decimal point must be present, and if the "e" is present then it must be followed by the exponent number. No half-finished vibes here. ๐ค
If there are no fields apart from the sign and initial sequence of digits (i.e., no decimal point or exponent indicator), then that initial sequence of digits should take one of the forms that Tcl_GetInt supports, described above. โฌ๏ธ
Heads up bestie: the use of "," as a decimal point is not supported, and no other sort of inter-digit separator should be present either. Sorry to my European girlies, the comma is not invited. ๐
โ Tcl_GetBoolean
Tcl_GetBoolean expects src to specify a boolean value.
- If src is any of
0,false,no, oroff, thenTcl_GetBooleanstores a zero value at*intPtr. ๐ซ - If src is any of
1,true,yes, oron, then 1 is stored at*intPtr. ๐ฏ
Any of these values may be abbreviated, and upper-case spellings are also acceptable. So go off, TRUE, YeS, we see you. ๐
๐ซถ Tcl_GetBool
Tcl_GetBool functions almost the same as Tcl_GetBoolean, but it has an additional parameter, flags, which can be used to specify whether the empty string or NULL is accepted as valid. That's the whole difference. Iconic, lowkey. โจ
๐ซ KEYWORDS ๐ซ
boolean, conversion, double, floating-point, integer
Okay that's the whole page, bestie, you ate it. ๐
This one's straight outta the Tcl source and it's filed under Tcl_GetInt(3tcl) โ go convert something cute. Byeee! ๐ฆโจ
๐ฆ 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) 1989-1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms