2007-11-24 23:12:41 limits.c (32, 64-bit)
This is a slightly modified bit of code from pp13-14 of Core Mac OS X And Unix Programming from Dalrymple and Hillegass, to display min/max limits of various built-in C primitives. I added some extra things to examine and then compiled for the 32 and 64-bit cases below.

( c )
  1  #include <limits.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 int main( int argc, char *argv[] ) {
6 printf( " type: bytes %20s %20s %20s\n", "min value", "max value", "max unsigned" );
7 printf( " char: %5ld %20d %20d %20u\n", sizeof(char), CHAR_MIN, CHAR_MAX, UCHAR_MAX );
8 printf( " short: %5ld %20d %20d %20u\n", sizeof(short), SHRT_MIN, SHRT_MAX, USHRT_MAX );
9 printf( " int: %5ld %20d %20d %20u\n", sizeof(int), INT_MIN, INT_MAX, UINT_MAX );
10 printf( " long: %5ld %20ld %20ld %20lu\n", sizeof(long), LONG_MIN, LONG_MAX, ULONG_MAX );
11 #ifdef LLONG_MIN
12 printf( " long long: %5ld %20lld %20lld %20llu\n", sizeof(long long),
13 LLONG_MIN, LLONG_MAX, (long long)ULLONG_MAX );
14 #endif
15 printf( " float: %5ld\n", sizeof(float));
16 printf( " void *: %5ld\n", sizeof(void *));
17 printf( " double: %5ld\n", sizeof(double));
18 printf( "long double: %5ld\n", sizeof(long double));
19 printf( " long bit: %5d\n", LONG_BIT);
20 printf( " word bit: %5d\n", WORD_BIT);
21 printf( " size_t: %5ld\n", sizeof(SIZE_T_MAX));
22 printf( " ssize_t: %5ld\n", sizeof(SSIZE_MAX));
23 return EXIT_SUCCESS;
24 }


Output produced from my x86-based Mac in normal 32-bit mode:

  1  [~/Programming/C]% gcc -arch i386 -o limits limits.c
2 [~/Programming/C]% ./limits
3 type: bytes min value max value max unsigned
4 char: 1 -128 127 255
5 short: 2 -32768 32767 65535
6 int: 4 -2147483648 2147483647 4294967295
7 long: 4 -2147483648 2147483647 4294967295
8 long long: 8 -9223372036854775808 9223372036854775807 18446744073709551615
9 float: 4
10 void *: 4
11 double: 8
12 long double: 16
13 long bit: 32
14 word bit: 32
15 size_t: 4
16 ssize_t: 4


and for the 64-bit case:

  1  [~/Programming/C]% gcc -arch x86_64 -o limits64 limits.c
2 [~/Programming/C]% ./limits64
3 type: bytes min value max value max unsigned
4 char: 1 -128 127 255
5 short: 2 -32768 32767 65535
6 int: 4 -2147483648 2147483647 4294967295
7 long: 8 -9223372036854775808 9223372036854775807 18446744073709551615
8 long long: 8 -9223372036854775808 9223372036854775807 18446744073709551615
9 float: 4
10 void *: 8
11 double: 8
12 long double: 16
13 long bit: 64
14 word bit: 32
15 size_t: 8
16 ssize_t: 8
Leave a comment