| C User's Guide |
ANSI/ISO C Data Representations
This appendix describes how ANSI 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 to C code. This appendix is organized into the following sections:
Storage Allocation
The following table shows the data types and how they are represented.
TABLE A-1 Storage Allocation for Data Types charelementsA single 8-bit byte aligned on a byte boundary. shortintegersHalfword (two bytes or 16 bits), aligned on a two-byte boundary int32 bits on v8 (four bytes or one word), aligned on a four-byte boundary long32 bits on v8 (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 long1(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 boundaryfloat32 bits (four bytes or one word), aligned on a four-byte boundary. A floathas asignbit, 8-bit exponent, and 23-bit fraction.double64 bits (eight bytes or two words), aligned on an eight-byte boundary (SPARC) or aligned on a four-byte boundary (Intel). A doubleelement has asignbit, an 11-bit exponent and a 52-bit fraction.long doublev8 (SPARC) 128 bits (16 bytes or four words), aligned on an eight-byte boundary. A long doubleelement has asignbit, a 15-bit exponent and a 112-bit fraction.
v9 (SPARC) 128 bits (16 bytes or four words), aligned on a 16 byte boundary. Along doubleelement has asignbit, a 15-bit exponent and a 112-bit fraction.
(Intel) 96 bits (12 bytes or three words) aligned on a four-byte boundary. Along doubleelement has asignbit, a 16-bit exponent, and a 64-bit fraction. 16 bits are unused.
1 long longis not available in-Xcmode.
Data Representations
Bit numberings of any given data element depend on the architecture in use: SPARCstationTM 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 Representations
Integer types used in ANSI C are
short,int,long, andlonglong:
TABLE A-2 Representation of short8 - 15 Byte 0 (SPARC)
Byte 1 (Intel)0 - 7 Byte 1 (SPARC)
Byte 0 (Intel)
TABLE A-3 Representation of int24 - 31 Byte 0 (SPARC)
Byte 3 (Intel)16 - 23 Byte 1 (SPARC)
Byte 2 (Intel)8 - 15 Byte 2 (SPARC)
Byte 1 (Intel)0 - 7 Byte 3 (SPARC)
Byte 0 (Intel)
TABLE A-5 Representation of long long156 - 63 Byte 0 (SPARC)
Byte 7 (Intel)48 - 55 Byte 1 (SPARC)
Byte 6 (Intel)40 - 47 Byte 2 (SPARC)
Byte 5 (Intel)32 - 39 Byte 3 (SPARC)
Byte 4 (Intel)24 - 31 Byte 4 (SPARC)
Byte 3 (Intel)16 - 23 Byte 5 (SPARC)
Byte 2 (Intel)8 - 15 Byte 6(SPARC)
Byte 1 (Intel)0 - 7 Byte 7 (SPARC)
Byte 0 (Intel)
1 long longis not available in-Xcmode.
Floating-Point Representations
float,double, andlong doubledata elements are represented according to the ANSI/ISO IEEE 754-1985 standard. The representation is:
- s =
sign- e = biased exponent
- j is the leading bit, determined by the value of e. In the case of
longdouble(Intel), the leading bit is explicit; in all other cases, it is implicit.- f = fraction
- u means that the bit can be either 0 or 1.
The following tables show the position of the bits.
TABLE A-6 floatRepresentation31 Sign 23 - 30 Exponent 0 - 22 Fraction
TABLE A-7 doubleRepresentation63 Sign 52 - 62 Exponent 0 - 51 Fraction
TABLE A-8 long doubleRepresentation (SPARC)127 Sign 112 - 126 Exponent 0 - 111 Fraction
TABLE A-9 longdoubleRepresentation (Intel)80 - 95 Unused 79 Sign 64 - 78 Exponent 63 Leading bit 0 - 62 Fraction
For further information, refer to the Numerical Computation Guide.
Exceptional Values
floatanddoublenumbers 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 oflongdouble, the leading bit is implicit (SPARC) or explicit (Intel); this bit is 1 for normal numbers, and 0 for subnormal numbers.
Hexadecimal Representation of Selected Numbers
The following tables show the hexadecimal representations.
For further information, refer to the Numerical Computation Guide.
Pointer Representation
A pointer in C occupies four bytes. The
NULLvalue pointer is equal to zero.Array Storage
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
charelements. The maximum number of characters allowed in a string literal or wide string literal (after concatenation) is 4,294,967,295.
TABLE A-15 Automatic Array Types and Storage char4,294,967,295 2,305,843,009,213,693,951 short2,147,483,647 1,152,921,504,606,846,975 int1,073,741,823 576,460,752,303,423,487 long1,073,741,823 288,230,376,151,711,743 float1,073,741,823 576,460,752,303,423,487 double536,870,911 288,230,376,151,711,743 long double268,435,451 144,115,188,075,855,871 long long1536,870,911 288,230,376,151,711,743
1 Not valid in -Xcmode
Static and global arrays can accommodate many more elements.
Arithmetic Operations on Exceptional Values
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 tables explain the abbreviations:
TABLE A-16 Abbreviation Usage Num Subnormal or normal number Inf Infinity (positive or negative) NaN Not a number Uno Unordered
The tables that follow describe the types of values that result from arithmetic operations performed with combinations of different types of operands.
TABLE A-17 Addition and Subtraction Results Right Operand Left Operand 0 Num Inf NaN 0 0 Num Inf NaN Num Num See Note Inf NaN Inf Inf Inf See Note NaN NaN NaN NaN NaN NaN
Note Num + Num could be Inf, rather than Num, when the result is too large (overflow). Inf + Inf = NaN when the infinities are of oppositesign.
TABLE A-18 Multiplication Results Right Operand Left Operand 0 Num Inf NaN 0 0 0 NaN NaN Num 0 Num Inf NaN Inf NaN Inf Inf NaN NaN NaN NaN NaN NaN
TABLE A-19 Division Results Right Operand Left Operand 0 Num Inf NaN 0 NaN 0 0 NaN Num Inf Num 0 NaN Inf Inf Inf NaN NaN NaN NaN NaN NaN NaN
TABLE A-20 Comparison Results Right Operand Left Operand 0 +Num +Inf NaN 0 = < < Uno +Num > The result of the comparison < Uno +Inf > > = Uno NaN Uno Uno Uno Uno
Note NaN compared with NaN is unordered, and results in inequality. +0 compares equal to -0.
Argument-Passing Mechanism
This section describes how arguments are passed in ANSI/ISO C.
All arguments to C functions are passed by value.
Actual arguments are passed in the reverse order from which they are declared in a function declaration.
Actual arguments which are expressions are evaluated before the function reference. The result of the expression is then placed in a register or pushed onto the stack.
Functions return
integerresults in register%o0,floatresults in register%f0, anddoubleresults in registers%f0and%f1.
long long1 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%i0and%i1, with similar ordering.All arguments, except
doubles andlongdoubles, are passed as four-byte values. Adoubleis passed as an eight-byte value. The first six four-byte values (doublecounts as 8) are passed in registers%o0through%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. Alongdoubleispassed 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.
Functions return
integerresults in register%eax.
long longresults are returned in registers%edxand%eax. Functions returnfloat,double, andlongdoubleresults in register%st(0).All arguments, except
structs,unions,longlongs,doublesandlongdoubles, are passed as four-byte values; alonglongis passed as an eight-byte value, adoubleis passed as an eight-byte value, and alongdoubleis passed as a 12-byte value.
structsandunionsare copied onto the stack. The size is rounded up to a multiple of four bytes. Functions returningstructsandunionsare passed a hidden first argument, pointing to the location into which the returnedstructorunionis 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
1 Not available instructandunionreturns that is popped by the called function.-Xcmode.
|
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |