- 论坛徽章:
- 14
|
- // 《ISO/IEC 9899:201x Committee Draft — August 11, 2008》
- // The strtol, strtoll, strtoul,and strtoull functions return the converted
- // value, if any. If no conversion could be performed, zero is returned. If the correct value
- // is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
- // LLONG_MAX, ULONG_MAX,or ULLONG_MAX is returned (according to the return type
- // and sign of the value, if any), and the value of the macro ERANGE is stored in errno.
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- void test( const char* src )
- {
- int errno_save = errno;
- char* endptr;
- unsigned long ret = strtoul( src, &endptr, 10 );
- if( errno == ERANGE )
- printf( "%s\n", "overflow/underflow" );
- else
- printf( "%lu\n", ret );
- errno = errno_save;
- }
- int main()
- {
- test( "4294967296" );
- test( "4294967295" );
- return 0;
- }
复制代码 |
|