Tcl_GetInt(3)
π Tcl_GetInt β bestie, we're converting strings today β¨
okay so this is the Tcl_GetInt(3) page from the Tcl Library Procedures manual, and it's literally about turning strings into numbers and booleans. no cap, it's giving "glow up your data types". π
β¨ NAME β¨
Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean β convert from string to integer, double, or boolean π
π¦ 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 use for error reporting. she's the messenger when things go wrong, periodt.const char *src(in) β the textual value that's getting converted. the main character, honestly.int *intPtr(out) β points to the place where the integer value converted fromsrcgets stored.double *doublePtr(out) β points to the place where the double-precision floating-point value converted fromsrcgets stored.char *charPtr(out) β points to the place where the boolean value (that's0or1) converted fromsrcgets stored.int flags(in) β0orTCL_NULL_OK. if you useTCL_NULL_OK, then the empty string orNULLwill result inTcl_GetBoolreturningTCL_OK, with*charPtrfilled with the value'\xFF'. lowkey feral behaviour but okay π
π₯ DESCRIPTION π₯
These procedures convert from strings to integers, or double-precision floating-point values, or booleans (which are represented as 0- or 1-valued integers). each of the procedures takes a src argument, converts it to an internal form of a particular type, and stores the converted value at the location indicated by the procedure's third argument. if all goes well, each of the procedures returns TCL_OK. π if src does not have the proper syntax for the desired type then TCL_ERROR is returned, an error message is left in the interpreter's result, and nothing is stored at *intPtr or *doublePtr. like, not even a little bit. the vibe check failed, bestie. π
π Tcl_GetInt π
Tcl_GetInt expects src to consist of a collection of integer digits, optionally signed and optionally preceded and followed by white space. and now for the base reveal, the way that:
- if the first two characters of
srcafter the optional white space and sign areβ0xβthensrcis expected to be in hexadecimal form; - otherwise, if the first such characters are
β0dβthensrcis expected to be in decimal form; - otherwise, if the first such characters are
β0oβthensrcis expected to be in octal form; - otherwise, if the first such characters are
β0bβthensrcis expected to be in binary form; - otherwise,
srcis expected to be in decimal form.
okay that's a whole aesthetic of number bases and honestly? iconic. π
π Tcl_GetDouble π
Tcl_GetDouble expects src to consist of a floating-point number, which is: 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 the fields may be omitted, except that 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 orphan e, she needs her number. π
if there are no fields apart from the sign and initial sequence of digits (i.e., no decimal point or exponent indicator), that initial sequence of digits should take one of the forms that Tcl_GetInt supports, described above.
the use ofβ,βas a decimal point is not supported, nor should any other sort of inter-digit separator be present. so no1,5bestie, that's not it. π
π«Ά Tcl_GetBoolean π«Ά
Tcl_GetBoolean expects src to specify a boolean value.
- if
srcis any of0,false,no, oroff, thenTcl_GetBooleanstores a zero value at*intPtr. - if
srcis any of1,true,yes, oron, then 1 is stored at*intPtr.
any of these values may be abbreviated, and upper-case spellings are also acceptable. so Y, N, TRUE, Off β all slay, all valid. β¨
π§ 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. she's Tcl_GetBoolean's cousin with extra boundaries, we respect her. π
β KEYWORDS β
boolean, conversion, double, floating-point, integer
and that's the whole page, bestie π¦ this came out of the Tcl manual (source is Tcl, and the page signs off as Tcl_GetInt(3)) β go forth and convert 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
- 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