4.1.5 Internal representation and value area of data

This section explains the internal representation and value area of each type for the data handled by the CC-RL.

(1)

Integer type

(a)

Internal representation

The leftmost bit in an area is a sign bit with a signed type. The value of a signed type is expressed as 2' s complement.

Figure 4.1

Internal Representation of Integer Type

 

_Bool

Only the 0th bit has meaning. Bits 1 to 7 are undefined.

When the -lang=c and -strict_std options are specified, _Bool type will cause a C90 violation error.

 

char

A plain char type not specified as signed or unsigned has the same representation as unsigned char.

When the -signed_char option is used, a plain char type has the same representation as signed char.

 

signed char (no sign bit for unsigned)

 

short (no sign bit for unsigned)

 

int (no sign bit for unsigned)

 

long (no sign bit for unsigned)

 

long long (no sign bit for unsigned)

When the -lang=c and -strict_std options are specified, long long type will cause a C90 violation error.

 

(b)

Value area

Table 4.9

Value Area of Integer Type

Type

Value Area

_Bool

0 to 1

signed char

-128 to +127

signed short

-32768 to +32767

signed int

-32768 to +32767

signed long

-2147483648 to +2147483647

signed long long

-9223372036854775808 to +9223372036854775807

(unsigned) char

0 to 255

unsigned short

0 to 65535

unsigned int

0 to 65535

unsigned long

0 to 4294967295

unsigned long long

0 to 18446744073709551615

(2)

Floating-point type

(a)

Internal representation

Internal Representation of floating-point data type conforms to IEC 60559:1989 (IEEE 754-1985)Note. The leftmost bit in an area of a sign bit. If the value of this sign bit is 0, the data is a positive value; if it is 1, the data is a negative value.

Note

IEEE: Institute of Electrical and Electronics Engineers
IEEE754 is a standard to unify specifications such as the data format and numeric range in systems that handle floating-point operations.

Figure 4.2

Internal Representation of Floating-Point Type

 

float

S: Sign bit of mantissa

E: Exponent (8 bits)

M: Mantissa (23 bits)

 

double, long double

S: Sign bit of mantissa

E: Exponent (11 bits)

M: Mantissa (52 bits)

 

When the option -dbl_size=4 is used, it has the same representation as type float. Even if you write type double, it will be treated as if you had written type float. Similarly, if you write long double, it will be treated as if you had written type float.

When the option dbl_size=8 is used, it is represented in 64 bits.

 

(b)

Value area

Table 4.10

Value Area of Floating-Point Type

Type

Value Area

float

1.17549435E-38F to 3.40282347E+38F

double

2.2250738585072014E-308 to 1.7976931348623158E+308

long double

2.2250738585072014E-308 to 1.7976931348623158E+308

(3)

Pointer type

(a)

Internal representation

The internal representation of a near pointer is a 16-bit unsigned type and that of a far pointer is a 32-bit unsigned type.

The most significant byte of a far pointer is undetermined.

The internal representation of a null pointer constant (NULL) has a value of 0. (Note that the byte corresponding to the undefined byte of the far pointer is not always 0.)

Therefore, for both the near and far pointers, access to address 0 is not guaranteed.

Correct operation is not guaranteed if the value of a far pointer exceeds 0xfffff.

Do not allocate a function or a variable to address 0x0f0000 or access the address.

Figure 4.3

Internal Representation of Pointer Type

 

near pointer

 

far pointer

 

(4)

Enumerated type

(a)

Internal representation

The internal representation of an enumerated type depends on the range of the enumerator value.

<1>

When option -signed_char is not specified

Minimum Value of Enumerator

Maximum Value of Enumerator

Type of Internal Representation

Remark

-128

127

signed char

 

0

255

char

When the range is 0 to 127, this type is used

Others

signed short

 

<2>

When option -signed_char is specified

Minimum Value of Enumerator

Maximum Value of Enumerator

Type of Internal Representation

Remark

-128

127

char

When the range is 0 to 127, this type is used

0

255

unsigned char

 

Others

signed short

 

(5)

Array type

(a)

Internal representation

The internal representation of an array type arranges the elements of an array in the form that satisfies the alignment condition (alignment) of the elements

Example

char    a[8] = {1, 2, 3, 4, 5, 6, 7, 8};

 

The internal representation of the array shown above is as follows.

Figure 4.4

Internal Representation of Array Type

(6)

Structure type

(a)

Internal representation

In a single structure, members are allocated from the head of the structure in the order of declaration. The internal representation of a structure type arranges the elements of a structure in a form that satisfies the alignment condition of the elements.

The alignment condition for the largest member of a structure is used as the alignment condition for the whole of the structure. This rule is also applied recursively when members are structures or unions.

The size of a structure is a multiple of the "alignment condition for the whole of the structure". Therefore, this size includes the unused area that is created to guarantee the alignment condition of the next data when the end of a structure does not match the alignment condition of that structure.

Example 1.

struct {
        short           s1;
        signed long     s2;
        char            s3;
        signed long     s4;
} s;

 

The internal representation of the structure shown above is as follows.

Figure 4.5

Internal Representation of Structure Type (without Structure Packing Specification)

Figure 4.6

Internal Representation of Structure Type (with Structure Packing Specification)

 

Example 2.

struct {
        short           s1;
        char            s2;
} s;

 

The internal representation of the structure shown above is as follows.

Figure 4.7

Internal Representation of Structure Type (without Structure Packing Specification)

Figure 4.8

Internal Representation of Structure Type (with Structure Packing Specification)

 

For details on the structure packing specification, see "-pack".

(7)

Union type

(a)

Internal representation

The alignment condition for the largest member of a union is used as the alignment condition for the whole of the union. This rule is also applied recursively when members are structures or unions.

Example

union {
        int     u1;
        short   u2;
        char    u3;
        long    u4;
} tag;

 

The internal representation of the union shown in the above example is as follows.

Figure 4.9

Internal Representation of Union Type

 

(8)

Bit field

(a)

Internal representation

The types that can be specified for bit fields are _Bool, char, signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long, signed long long, unsigned long long, and enumerated types.

Although only (signed or unsigned) int is allowed in C90, all of the above types are valid for bit fields in CC-RL if the -strict_std option is not used.

With the -strict_std option, the _Bool, signed long long, and unsigned long long types will cause a C90 violation error.

A bit field is allocated starting from the least significant bit for the type specified in the declaration of the bit field.

When an attempt is made to allocate a bit field from the bit contiguous to the previous bit field and the location of the end of the bit field after allocation exceeds the location of adding the "bit width of declared type" to the boundary that is previous to satisfaction of the alignment condition for the bit field, the bit field is allocated to an area starting from the first boundary that satisfies the alignment condition after the previous bit field.

-

The bit field of a type not specified as signed or unsigned is handled as unsigned.
However, when the -signed_bitfield option is specified, it is handled as signed.

-

Bit fields within an allocation unit are allocated from the lower order (LSB) toward the higher order (MSB).

Example 1.

struct S{
        char            a;
        char            b:2;
        signed char     c:3;
        unsigned char   d:4;
        int             e;
        short           f:5;
        int             g:6;
        unsigned char   h:2;
        unsigned int    i:2;
};

 

The internal representation for the bit field in the above example is as follows.

Figure 4.10

Internal Representation of Bit Field (without Structure Packing Specification)

 

sizeof(struct S)=8

Figure 4.11

Internal Representation of Bit Field (with Structure Packing Specification)

 

sizeof(struct S)=7

Example 2.

struct S{
        char    f1:4;
        int     f2:5;
        int     f3:6;
};

 

The internal representation for the bit field in the above example is as follows.

Figure 4.12

Internal Representation of Bit Field

 

sizeof(struct S)=2

 

Example 3.

struct S{
        long    f1:4;
};

 

The internal representation for the bit field in the above example is as follows.

Figure 4.13

Internal Representation of Bit Field (without Structure Packing Specification)

 

sizeof(struct S)=2

Figure 4.14

Internal Representation of Bit Field (with Structure Packing Specification)

 

sizeof(struct S)=1

 

For details on the structure packing specification, see "-pack".

(9)

Alignment

(a)

Alignment condition for basic type

Alignment condition for basic type is as follows.

Table 4.11

Alignment Condition for Basic Type

Basic Type

Alignment Conditions

(unsigned) char

_Bool type

1-byte boundary

Others

2-byte boundary

(b)

Alignment condition for enumerated type

Alignment condition for enumerated type is as follows.

<1>

When option -signed_char is not specified

Minimum Value of Enumerator

Maximum Value of Enumerator

Type of Internal Representation

Alignment Condition

-128

127

signed char

1

0

255

char

1

Others

signed short

2

<2>

When option -signed_char is specified

Minimum Value of Enumerator

Maximum Value of Enumerator

Type of Internal Representation

Alignment Condition

-128

127

char

1

0

255

unsigned char

1

Others

signed short

2

(c)

Alignment condition for array type

The alignment condition for an array type is the same as that for the array elements.

(d)

Alignment condition for pointers

The alignment condition (value) for near and far pointers is 2.

(e)

Alignment condition for union type

The alignment conditions for a union type are the same as those of the structure's member whose type has the largest alignment condition.

(f)

Alignment condition for structure type

The alignment conditions for a structure type are the same as those of the structure's member whose type has the largest alignment condition.

(g)

Alignment condition for function argument

See "9.1 Function Call Interface".

(h)

Alignment condition for function

The alignment condition for a function is a 1-byte boundary.