A P P E N D I X B |
ISO C Data Representations |
This appendix describes how ISO C represents data in storage and the mechanisms for passing arguments to functions. It is intended as a guide to programmers who want to write or use modules in languages other than C and have those modules interface with C code.
The following table shows the data types and how they are represented.
Note - Storage allocated on the stack (identifiers with internal, or automatic, linkage) should be limited to two gigabytes or less. |
Halfword (two bytes or 16 bits), aligned on a two-byte boundary |
|
32 bits (four bytes or one word), aligned on a four-byte boundary |
|
32 bits on v8 and Intel (four bytes or one word), aligned on a four-byte boundary 64 bits on v9 (eight bytes or two words) aligned on an eight-byte boundary) |
|
32 bits on v8 and Intel (four bytes or one word), aligned on a four-byte boundary 64 bits on v9 (eight bytes or two words) aligned on an eight-byte boundary) |
|
long long[1] |
(SPARC) 64 bits (eight bytes or two words), aligned on an eight-byte boundary (Intel) 64 bits (eight bytes or two words), aligned on a four-byte boundary |
32 bits (four bytes or one word), aligned on a four-byte boundary. A float has a sign bit, 8-bit exponent, and 23-bit fraction. |
|
64 bits (eight bytes or two words), aligned on an eight-byte boundary (SPARC) or aligned on a four-byte boundary (Intel). A double element has a sign bit, an 11-bit exponent and a 52-bit fraction. |
|
v8 (SPARC) 128 bits (16 bytes or four words), aligned on an eight-byte boundary. A long double element has a sign bit, a 15-bit exponent and a 112-bit fraction. v9 (SPARC) 128 bits (16 bytes or four words), aligned on a 16 byte boundary. A long double element has a sign bit, a 15-bit exponent and a 112-bit fraction. (Intel) 96 bits (12 bytes or three words) aligned on a four-byte boundary. A long double element has a sign bit, a 16-bit exponent, and a 64-bit fraction. 16 bits are unused. |
Bit numbering of any given data element depend on the architecture in use: SPARCstation machines use bit 0 as the least significant bit, with byte 0 being the most significant byte. The tables in this section describe the various representations.
Integer types used in ISO C are short, int, long, and long long:
float, double, and long double data elements are represented according to the ISO IEEE 754-1985 standard. The representation is:
The following tables show the position of the bits.
For further information, refer to the Numerical Computation Guide.
float and double numbers are said to contain a "hidden," or implied, bit, providing for one more bit of precision than would otherwise be the case. In the case of long double, the leading bit is implicit (SPARC) or explicit (Intel); this bit is 1 for normal numbers, and 0 for subnormal numbers.
s=u, e=255(max); f=.0uuu-uu; at least one bit must be nonzero |
|
s=u, e=2047(max); f=.0uuu-uu; at least one bit must be nonzero |
|
s=u, e=32767(max); f=.0uuu-uu; at least one bit must be nonzero |
|
The following tables show the hexadecimal representations.
For further information, refer to the Numerical Computation Guide.
A pointer in C occupies four bytes. A pointer in C occupies eight bytes on SPARC v9 architectures. The NULL value pointer is equal to zero.
Arrays are stored with their elements in a specific storage order. The elements are actually stored in a linear sequence of storage elements.
C arrays are stored in row-major order; the last subscript in a multidimensional array varies the fastest.
String data types are simply arrays of char elements. The maximum number of characters allowed in a string literal or wide string literal (after concatenation) is 4,294,967,295.
See Section B.1, Storage Allocation for information on the size limit of storage allocated on the stack.
long long[3] |
Static and global arrays can accommodate many more elements.
This section describes the results derived from applying the basic arithmetic operations to combinations of exceptional and ordinary floating-point values. The information that follows assumes that no traps or any other exception actions are taken.
The following table explains the abbreviations:
The following tables describe the types of values that result from arithmetic operations performed with combinations of different types of operands.
See[4] |
||||
SeeNum + Num could be Inf, rather than Num, when the result is too large (overflow). Inf + Inf = NaN when the infinities are of opposite sign. |
||||
Note - NaN compared with NaN is unordered, and results in inequality. +0 compares equal to -0. |
This section describes how arguments are passed in ISO C.
Functions return integer results in register %o0, float results in register %f0, and double results in registers %f0 and %f1.
long long[5] integers are passed in registers with the higher word order in %oN, and the lower order word in %o(N+1). In-register results are returned in %i0 and %i1, with similar ordering.
All arguments, except doubles and long doubles, are passed as four-byte values. A double is passed as an eight-byte value. The first six four-byte values (double counts as 8) are passed in registers %o0 through %o5. The rest are passed onto the stack. Structures are passed by making a copy of the structure and passing a pointer to the copy. A long double is passed in the same manner as a structure.
Upon return from a function, it is the responsibility of the caller to pop arguments from the stack. Registers described are as seen by the caller.
All integral arguments are passed as eight-byte values.
Floating-point arguments are passed in floating-point registers when possible.
Functions return integer results in register %eax.
long long results are returned in registers %edx and %eax. Functions return float, double, and long double results in register %st(0).
All arguments except structs, unions, long longs, doubles and long doubles are passed as four-byte values; a long long is passed as an eight-byte value, a double is passed as an eight-byte value, and a long double is passed as a 12-byte value.
structs and unions are copied onto the stack. The size is rounded up to a multiple of four bytes. Functions returning structs and unions are passed a hidden first argument, pointing to the location into which the returned struct or union is stored.
Upon return from a function, it is the responsibility of the caller to pop arguments from the stack, except for the extra argument for struct and union returns that is popped by the called function.
Copyright © 2002, Sun Microsystems, Inc. All rights reserved.