#include <stdio.h> // for printf()
#include <limits.h>
// integral limits, including char
int main()
{
unsigned char c = -1;
printf("unsigned char(-1):\t%d\n", c);
printf("UCHAR_MAX:\t\t%d\n", UCHAR_MAX);
c = UCHAR_MAX+1; // compiler warning: overflow
printf("unsigned char(UCHAR_MAX+1):\t%d\n", c);
c = 256; // compiler warning: overflow
printf("unsigned char(256):\t\t%d\n", c);
printf("CHAR_MAX:\t %d\n", CHAR_MAX);
printf("CHAR_MIN:\t%d\n", CHAR_MIN);
printf("-CHAR_MAX-1:\t%d\n", -CHAR_MAX-1);
printf("SHRT_MAX:\t %d\n", SHRT_MAX);
printf("SHRT_MIN:\t%d\n", SHRT_MIN);
printf("-SHRT_MAX-1:\t%d\n", -SHRT_MAX-1);
printf("INT_MAX:\t %d\n", INT_MAX);
printf("INT_MIN:\t%d\n", INT_MIN);
printf("-INT_MAX-1:\t%d\n", -INT_MAX-1);
printf("-1:\t\t%u\n", -1); // UINT_MAX
printf("UINT_MAX:\t%u\n", UINT_MAX);
printf("unsigned int min: %u\n", UINT_MAX+1);
printf("-2:\t\t%u\n", -2); // UINT_MAX-1
printf("UINT_MAX-1:\t%u\n", UINT_MAX-1);
printf("LONG_MAX:\t %ld\n", LONG_MAX);
printf("LONG_MIN:\t%ld\n", LONG_MIN);
printf("-LONG_MAX-1:\t%ld\n", -LONG_MAX-1);
printf("-1L:\t\t%lu\n", -1L); // ULONG_MAX
printf("ULONG_MAX:\t%lu\n", ULONG_MAX);
printf("unsigned long min: %lu\n", ULONG_MAX+1);
printf("LLONG_MAX:\t %Ld\n", LLONG_MAX);
printf("LLONG_MIN:\t%Ld\n", LLONG_MIN);
printf("-LLONG_MAX-1:\t%Ld\n", -LLONG_MAX-1);
printf("-1LL:\t\t%Lu\n", -1LL); // ULLONG_MAX
printf("ULLONG_MAX:\t%Lu\n", ULLONG_MAX);
printf("unsigned long long min: %Lu\n", ULLONG_MAX+1);
return 0;
}
/*
gcc intlimits.c -o intlimits
intlimits.c: In function ‘main’:
intlimits.c:10:7: warning: unsigned conversion from ‘int’ to
‘unsigned char’ changes value from ‘256’ to ‘0’ [-Woverflow]
10 | c = UCHAR_MAX+1; // compiler warning: overflow
| ^~~~~~~~~
intlimits.c:12:7: warning: unsigned conversion from ‘int’ to
‘unsigned char’ changes value from ‘256’ to ‘0’ [-Woverflow]
12 | c = 256; // compiler warning: overflow
| ^~~
./intlimits
unsigned char(-1): 255
UCHAR_MAX: 255
unsigned char(UCHAR_MAX+1): 0
unsigned char(256): 0
CHAR_MAX: 127
CHAR_MIN: -128
-CHAR_MAX-1: -128
SHRT_MAX: 32767
SHRT_MIN: -32768
-SHRT_MAX-1: -32768
INT_MAX: 2147483647
INT_MIN: -2147483648
-INT_MAX-1: -2147483648
-1: 4294967295
UINT_MAX: 4294967295
unsigned int min: 0
-2: 4294967294
UINT_MAX-1: 4294967294
LONG_MAX: 9223372036854775807
LONG_MIN: -9223372036854775808
-LONG_MAX-1: -9223372036854775808
-1L: 18446744073709551615
ULONG_MAX: 18446744073709551615
unsigned long min: 0
LLONG_MAX: 9223372036854775807
LLONG_MIN: -9223372036854775808
-LLONG_MAX-1: -9223372036854775808
-1LL: 18446744073709551615
ULLONG_MAX: 18446744073709551615
unsigned long long min: 0
*/
Comments
Post a Comment