| 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

- [ws] is an optional string of spaces;
- [sn] is an optional sign ('+', '-', or special "small" minus used in TI-Basic);
- [0] is an optional zero (0);
- [x] is an optional 'x' or 'X';
- [ddd] is an optional string of digits.

strtol stops reading the string at the first character it doesn't recognize.

- If radix is between 2 and 36, the long integer is expressed in base radix.
- If radix is 0, the first few characters of str determine the base of the value being converted.

  First character | Second character | String interpreted as
  0 0 1 - 9 | 1 - 7 x or X | Octal Hexadecimal Decimal

- If radix is 1, less than 0 or greater than 36, it is considered to be an invalid value.

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