1Tcl_GetInt(3) Tcl Library Procedures Tcl_GetInt(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean - convert from string to
9 integer, double, or boolean
10
12 #include <tcl.h>
13
14 int
15 Tcl_GetInt(interp, src, intPtr)
16
17 int
18 Tcl_GetDouble(interp, src, doublePtr)
19
20 int
21 Tcl_GetBoolean(interp, src, boolPtr)
22
24 Tcl_Interp *interp (in) Interpreter to use for error
25 reporting.
26
27 const char *src (in) Textual value to be converted.
28
29 int *intPtr (out) Points to place to store integer
30 value converted from src.
31
32 double *doublePtr (out) Points to place to store double-
33 precision floating-point value con‐
34 verted from src.
35
36 int *boolPtr (out) Points to place to store boolean
37 value (0 or 1) converted from src.
38______________________________________________________________________________
39
40
42 These procedures convert from strings to integers or double-precision
43 floating-point values or booleans (represented as 0- or 1-valued inte‐
44 gers). Each of the procedures takes a src argument, converts it to an
45 internal form of a particular type, and stores the converted value at
46 the location indicated by the procedure's third argument. If all goes
47 well, each of the procedures returns TCL_OK. If src does not have the
48 proper syntax for the desired type then TCL_ERROR is returned, an error
49 message is left in the interpreter's result, and nothing is stored at
50 *intPtr or *doublePtr or *boolPtr.
51
52 Tcl_GetInt expects src to consist of a collection of integer digits,
53 optionally signed and optionally preceded and followed by white space.
54 If the first two characters of src after the optional white space and
55 sign are “0x” then src is expected to be in hexadecimal form; other‐
56 wise, if the first such characters are “0o” then src is expected to be
57 in octal form; otherwise, if the first such characters are “0b” then
58 src is expected to be in binary form; otherwise, if the first such
59 character is “0” then src is expected to be in octal form; otherwise,
60 src is expected to be in decimal form.
61
62 Tcl_GetDouble expects src to consist of a floating-point number, which
63 is: white space; a sign; a sequence of digits; a decimal point “.”;
64 a sequence of digits; the letter “e”; a signed decimal exponent; and
65 more white space. Any of the fields may be omitted, except that the
66 digits either before or after the decimal point must be present and if
67 the “e” is present then it must be followed by the exponent number. If
68 there are no fields apart from the sign and initial sequence of digits
69 (i.e., no decimal point or exponent indicator), that initial sequence
70 of digits should take one of the forms that Tcl_GetInt supports,
71 described above. The use of “,” as a decimal point is not supported nor
72 should any other sort of inter-digit separator be present.
73
74 Tcl_GetBoolean expects src to specify a boolean value. If src is any
75 of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at
76 *boolPtr. If src is any of 1, true, yes, or on, then 1 is stored at
77 *boolPtr. Any of these values may be abbreviated, and upper-case
78 spellings are also acceptable.
79
80
82 boolean, conversion, double, floating-point, integer
83
84
85
86Tcl Tcl_GetInt(3)