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 char
elementsA single 8-bit byte aligned on a byte boundary. short
integersHalfword (two bytes or 16 bits), aligned on a two-byte boundary int
32 bits on v8 (four bytes or one word), aligned on a four-byte boundary long
32 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 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 boundaryfloat
32 bits (four bytes or one word), aligned on a four-byte boundary. A float
has asign
bit, 8-bit exponent, and 23-bit fraction.double
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 asign
bit, an 11-bit exponent and a 52-bit fraction.long double
v8 (SPARC) 128 bits (16 bytes or four words), aligned on an eight-byte boundary. A long double
element has asign
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. Along double
element has asign
bit, a 15-bit exponent and a 112-bit fraction.
(Intel) 96 bits (12 bytes or three words) aligned on a four-byte boundary. Along double
element has asign
bit, a 16-bit exponent, and a 64-bit fraction. 16 bits are unused.
1 long long
is not available in-Xc
mode.
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
, andlong
long
:
TABLE A-2 Representation of short
8 - 15 Byte 0 (SPARC)
Byte 1 (Intel)0 - 7 Byte 1 (SPARC)
Byte 0 (Intel)
TABLE A-3 Representation of int
24 - 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 long
156 - 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 long
is not available in-Xc
mode.
Floating-Point Representations
float
,double
, andlong double
data 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
long
double
(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 float
Representation31 Sign 23 - 30 Exponent 0 - 22 Fraction
TABLE A-7 double
Representation63 Sign 52 - 62 Exponent 0 - 51 Fraction
TABLE A-8 long double
Representation (SPARC)127 Sign 112 - 126 Exponent 0 - 111 Fraction
TABLE A-9 long
double
Representation (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
float
anddouble
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 oflong
double
, 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
NULL
value 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
char
elements. 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 char
4,294,967,295 2,305,843,009,213,693,951 short
2,147,483,647 1,152,921,504,606,846,975 int
1,073,741,823 576,460,752,303,423,487 long
1,073,741,823 288,230,376,151,711,743 float
1,073,741,823 576,460,752,303,423,487 double
536,870,911 288,230,376,151,711,743 long double
268,435,451 144,115,188,075,855,871 long long
1536,870,911 288,230,376,151,711,743
1 Not valid in -Xc
mode
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
integer
results in register%o0
,float
results in register%f0
, anddouble
results in registers%f0
and%f1
.
long long
1 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
double
s andlong
doubles
, are passed as four-byte values. Adouble
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. Along
double
ispassed 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
integer
results in register%eax
.
long long
results are returned in registers%edx
and%eax
. Functions returnfloat
,double
, andlong
double
results in register%st(0)
.All arguments, except
structs
,unions
,long
longs
,doubles
andlong
doubles
, are passed as four-byte values; along
long
is passed as an eight-byte value, adouble
is passed as an eight-byte value, and along
double
is passed as a 12-byte value.
structs
andunions
are copied onto the stack. The size is rounded up to a multiple of four bytes. Functions returningstructs
andunions
are passed a hidden first argument, pointing to the location into which the returnedstruct
orunion
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
1 Not available instruct
andunion
returns that is popped by the called function.-Xc
mode.
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |