printf( "overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: \n" );
printf( "ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: \n" );
printf( "constants available at compile time: \n" );
errno = 0;
printf( "ULONG_MAX + ( ULONG_MAX/2 ) : %1lu \n", ULONG_MAX + ( ULONG_MAX / 2 ) );
perror( " error occured");
printf( "one value read at runtime: \n" );
errno = 0;
printf( "ULONG_MAX + argv-09 : %1lu \n", ULONG_MAX + strtoul( argv[ 9 ], NULL, 0 ) );
perror( " error occured");
printf( "similar val. from conversion: \n" );
errno = 0;
printf( "known at compile time : %1lu \n", (ulong)( (long double)ULONG_MAX * 1.5l ) );
perror( " error occured");
errno = 0;
printf( "one value read at runtime : %1lu \n", (ulong)( (long double)ULONG_MAX + (long double)( strtoul( argv[ 9 ], NULL, 0 ) ) ) );
perror( " error occured");
printf( "three different results for calculations which mathematical, user POV, should be the same. \n" );
printf( " \n" );
which here produces the output:
overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807:
ULONG_MAX + ( ULONG_MAX / 2 ), different calculations:
constants available at compile time:
ULONG_MAX + ( ULONG_MAX/2 ) : 9223372036854775806
error occured: Success
one value read at runtime:
ULONG_MAX + argv-09 : 9223372036854775806
error occured: Success
similar val. from conversion:
known at compile time : 18446744073709551615
error occured: Success
one value read at runtime : 0
error occured: Success
three different results for calculations which mathematical, user POV, should be the same.