wcstoull() — Convert a wide-character string to an unsigned long long integer

Standards

Standards / Extensions C or C++ Dependencies

z/OS® UNIX
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both

OS/390 V2R10

Format

#include <wchar.h>

unsigned long long wcstoull(const wchar_t * __restrict__nptr, 
                            wchar_t ** __restrict__endptr, int base);
Compile requirement: Use of this function requires the long long data type. See z/OS XL C/C++ Language Reference for information on how to make long long available.

General description

Converts the initial portion of the wide-character string pointed to by nptr to unsigned long long integer representation. First it decomposes the input wide-character string into three parts:
  1. An initial, possibly empty, sequence of white space wide characters (as specified by the iswspace() function).
  2. A subject sequence resembling an unsigned integer represented in some radix determined by the value of base.
  3. A final wide-character string of one or more unrecognized wide characters, including the terminating NULL character of the input wide-character string.

Then it attempts to convert the subject sequence to an unsigned long long integer, and returns the result.

If the value of base is zero, the expected form of the subject sequence is that of an integer constant as described in ISO/IEC 9899: subclause 6.1.3.2, optionally preceded by a plus or minus sign, but not including an integer suffix. If the value of base is between 2 and 36, the expected form of the subject sequence is a sequence of letters and digits from the portable character set representing an integer with the radix specified by base, optionally preceded by a plus or minus sign, but not including an integer suffix. The letters from a (or A) through z (or Z) are ascribed the values 10 to 35; only letters whose ascribed values are less than that of base are permitted. If the value of base is 16, the characters 0x or 0X may optionally precede the sequence of letters and digits, following the sign if present.

The subject sequence is defined as the longest initial sub-sequence of the input wide-character string, starting with the first non-white space wide character, that is of the expected form. The subject sequence contains no wide characters if the input wide-character string is empty or consists entirely of white space, or if the first non-white space wide character is other than a sign or a permissible letter or digit.

If the subject sequence has the expected form and the value of base is zero, the sequence of wide characters starting with the first digit is interpreted as an integer constant according to the rules of ISO/IEC 9899: subclause 6.1.3.2. If the subject sequence has the expected form and the value of base is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value as given above. If the subject sequence begins with a minus sign, the value resulting from the conversion is negated. A pointer to the final string is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer. In a locale other than the C or POSIX locale, additional implementation-defined subject sequence forms may be accepted.

If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer.

The behavior of this wide-character function is affected by the LC_CTYPE category of the current locale. If you change the category, undefined results can occur.

Since 0 and {ULLONG_MAX} are returned on error and 0 is also a valid return on success, an application wishing to check for error situations should set errno to 0, then call wcstoull(), then check errno.

Returned value

If successful, wcstoull() returns the converted value, if any.

If unsuccessful, wcstoull() returns 0 if no conversion could be performed. If the correct value is outside the range of representable values, wcstoull() returns ULLONG_MAX (ULONGLONG_MAX). If the value of base is not supported, wcstoull() returns 0.

If unsuccessful wcstoull() sets errno to one of the following values:

Error Code
Description
EINVAL
The value of base is not supported.
ERANGE
The conversion caused an overflow.

Example

 /* LongLong conversion */
  #define _LONG_LONG 1
  #include <stdio.h>
  #include <wchar.h>

  #define BASE 2

  int main(void)
  {
     wchar_t *wcs = L"1000e13 camels";
     wchar_t **endptr;
     unsigned long long answer;

     answer = wcstoull(wcs, endptr, BASE);
     printf("The input wide string used: `%ls`\n", wcs);
     printf("The unsigned long long produced: %llu\n", answer);
     printf("The substring of the input wide string that was not");
     printf(" converted to unsigned long long: `%ls`\n", *endptr);
  }

Related information