Wednesday, November 21, 2007

Finding the limits on Mac OS X PPC Architecture

The first exercise in Kernighan and Ritchie asks that we find out the ranges of char, short, int and long variables by writing a program. It also gives a hint just above this question by telling us that the symbolic constants are in the standard header files such as . Now all we have to do is to include this file in our program and access the variables.

So if we begin with the end in mind, here is our path
1. Print the ranges of variable class e.g. short, int
2. These values can be found in the header files such as
3. Find the header file
4. Get the ranges
5. Include the header file in your program
6. Access the variable values as symbolic constant

The tricky part is step 3 i.e. to find where the header file is located especially on my Mac. Here is how I found the file
1. I need to use command line and go to the root.
2. cd /
3. This file will most likely be in usr
4. cd /usr
5. There is an include directory. Our file will most likely be here.
6. cd include
7. OK. Doing ls in the include directory gave me a long list of files
8. Now I know that my Mac has powerpc architecture. So I went in the directory ppc
9. cd ppc
10. Found the file.

Now, of course, this is not as intuitive as above and there were some trial and error involved. But I will spare the details and just give the clean solution.

So the final location of the limits.h file is
/usr/include/ppc

And the ranges of the variables on my computer are
Size of Char 8
Size of Char Max 127
Size of Char Min -128
Size of int min -2147483648
Size of int max 2147483647
Size of long min -2147483648
Size of long max 2147483647
Size of short min -32768
Size of short max 32767
Size of unsigned char 255
Size of unsigned long 4294967295
Size of unsigned int 4294967295
Size of unsigned short 65535

0 Comments:

Post a Comment

<< Home