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 from src gets stored.
  • double *doublePtr (out) β€” points to the place where the double-precision floating-point value converted from src gets stored.
  • char *charPtr (out) β€” points to the place where the boolean value (that's 0 or 1) converted from src gets stored.
  • int flags (in) β€” 0 or TCL_NULL_OK. if you use TCL_NULL_OK, then the empty string or NULL will result in Tcl_GetBool returning TCL_OK, with *charPtr filled 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 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.

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 no 1,5 bestie, that's not it. πŸ’€

🫢 Tcl_GetBoolean 🫢

Tcl_GetBoolean expects src to specify a boolean value.

  • if src is any of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at *intPtr.
  • if src is any of 1, true, yes, or on, 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