324_Book

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Using sizeof, rather than a fixed value, is one step toward writing code that is portable across different machine types. We ran the code shown in Figure 2.4 on several different machines, giving the results shown in Figure 2.5. The machines used were: Linux: Intel Pentium II running Linux. NT: Sun: Intel Pentium II running Windows-NT. Sun Microsystems UltraSPARC running Solaris. Alpha: Compaq Alpha 21164 running Tru64 Unix. 2.1. INFORMATION STORAGE 31 code/data/show-bytes.c 1 2 3 4 5 6 7 8 9 void test_show_bytes(int val) { int ival = val; float fval = (float) ival; int *pval = &ival; show_int(ival); show_float(fval); show_pointer(pval); } code/data/show-bytes.c Figure 2.4: Byte Representation Examples. This code prints the byte representations of sample data objects. Machine Linux NT Sun Alpha Linux NT Sun Alpha Linux NT Sun Alpha Value 12,345 12,345 12,345 12,345 ½¾ ¿ ½¾ ¿ ½¾ ¿ ½¾ ¿ ¼ ¼ ¼ ¼ &ival &ival &ival &ival Type int int int int float float float float int * int * int * int * 39 39 00 39 00 00 46 00 3c 1c ef 80 30 30 00 30 e4 e4 40 e4 fa ff ff fc Bytes (Hex) 00 00 00 00 30 39 00 00 40 46...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online