strtol Function (tigcc.a)

stdlib.h

long strtol (const char *str, char **endptr, short radix);

Converts a string to a long integer using a given radix, with detection of overflows and errors.

strtol converts a character string str to a long integer value. str is a sequence of characters that can be interpreted as a long value. The characters must match this generic format:

[ws] [sn] [0] [x] [ddd]

where

strtol stops reading the string at the first character it doesn't recognize. The characters are interpreted according to the following table:

Value in str meant to be interpreted as Resulting Character Recognition
Octal Any character other than 0 to 7 will be unrecognized.
Decimal Any character other than 0 to 9 will be unrecognized.
A number in any other base Only the numerals and letters used to represent numbers in that base will be recognized (for example, if radix equals 5, only 0 to 4 will be recognized; if radix equals 20, only 0 to 9 and A to J will be recognized).

If endptr is not NULL, strtol sets the pointer variable pointed to by endptr to point to the character that stopped the scan (i.e. *endptr = &stopper). strtol returns the value of the converted string, or 0 on error. In a case of overflow, strtol returns LONG_MAX or LONG_MIN, depending of the sign.

Note: strtol is much more flexible than atol (or atoi), but as it is not built-in in the TIOS, usage of it makes the total size of the program much greater.


Uses: _du32u32, _mu32u32