Mark said:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:
#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0
Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won't it print the limit?
It would seem that you are using a <limits.h> not appropriate for your
compiler. Make sure that you don't have a mismatch. For comparison, I get
for my implementation:
#include <limits.h>
#include <stdio.h>
int main(void)
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
printf("Smallest signed long: %ld\n", LONG_MIN);
printf("Smallest signed int: %d\n", INT_MIN);
printf("Smallest signed short: %hd\n", SHRT_MIN);
printf("Smallest signed char: %d\n", SCHAR_MIN);
printf("Largest signed long long: %lld\n", LLONG_MAX);
printf("Largest unsigned long long: %llu\n", ULLONG_MAX);
printf("Largest signed long: %ld\n", LONG_MAX);
printf("Largest unsigned long: %lu\n", ULONG_MAX);
printf("Largest signed int: %d\n", INT_MAX);
printf("Largest unsigned int: %u\n", UINT_MAX);
printf("Largest signed short: %hd\n", SHRT_MAX);
printf("Largest unsigned short: %hu\n", USHRT_MAX);
printf("Largest signed char: %d\n", SCHAR_MAX);
printf("Largest unsigned char: %u\n", UCHAR_MAX);
return 0;
}
Smallest signed long long: -9223372036854775808
Smallest signed long: -2147483648
Smallest signed int: -2147483648
Smallest signed short: -32768
Smallest signed char: -128
Largest signed long long: 9223372036854775807
Largest unsigned long long: 18446744073709551615
Largest signed long: 2147483647
Largest unsigned long: 4294967295
Largest signed int: 2147483647
Largest unsigned int: 4294967295
Largest signed short: 32767
Largest unsigned short: 65535
Largest signed char: 127
Largest unsigned char: 255