4.1.6 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-RH.

(1)

Integer type

(a)

Internal representation

The leftmost bit in an area is a sign bit with a signed type (type declared without "unsigned"). The value of a signed type is expressed as 2' s complement.

Figure 4.1

Internal Representation of Integer Type

 

(b)

Value area

Table 4.9

Value Area of Integer Type

Type

Value Area

charNote

-128 to +127

short

-32768 to +32767

int

-2147483648 to +2147483647

long

-2147483648 to +2147483647

long long

-9223372036854775808 to +9223372036854775807

unsigned char

0 to 255

unsigned short

0 to 65535

unsigned int

0 to 4294967295

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 IEEE754Note. 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

(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 pointer type is the same as that of an unsigned int type.

Figure 4.3

Internal Representation of Pointer Type

(4)

Enumerate type

(a)

Internal representation

The internal representation of an enumerate type is the same as that of a signed int type. The leftmost bit in an area of a sign bit.

Figure 4.4

Internal Representation of Enumerate Type

 

When the -Xenum_type=auto option is specified, see "(30) Enumerate type specifier".

(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.5

Internal Representation of Array Type

(6)

Structure type

(a)

Internal representation

The internal representation of a structure type arranges the elements of a structure in a form that satisfies the alignment condition of the elements.

Example

struct {
        short   s1;
        int     s2;
        char    s3;
        long    s4;
} tag;

 

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

Figure 4.6

Internal Representation of Structure Type

 

For the internal representation when the structure type packing function is used, see "4.2.4.8 Structure type packing".

(7)

Union type

(a)

Internal representation

A union is considered as a structure whose members all start with offset 0 and that has sufficient size to accommodate any of its members. The internal representation of a union type is like each element of the union is placed separately at the same address.

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.7

Internal Representation of Union Type

(8)

Bit field

(a)

Internal representation

The most significant bit of a bit field declared as a signed type, or without an explicit sign declaration, will be the sign bit. The first bit field to be declared will be allocated starting from the least significant bit in the area with the sign of the type when the bit field was declared. If the alignment condition of the type specified in the declaration of a bit field is exceeded as a result of allocating an area that immediately follows the area of the preceding bit field to the bit field, the area is allocated starting from a boundary that satisfies the alignment condition.

You can allocate the members of a bit field starting from the most significant bit using the -Xbit_order=left option or by specifying #pragma bit_order left. See "4.2.4.9 Bit field assignment" for details.

Example 1.

struct {
        unsigned int    f1:30;
        int             f2:14;
        unsigned int    f3:6;
} flag;

 

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

Figure 4.8

Internal Representation of Bit Field

Example 2.

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

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

Figure 4.9

Internal Representation of Bit Field

 

The ANSI standards do allow only int and unsigned int types to be specified for a bit field, but the CC-RH allows char, short, long, long long and those unsigned types.

For the internal representation of bit field when the structure type packing function is used, see "4.2.4.8 Structure type packing".

(9)

Alignment condition

(a)

Alignment condition for basic type

Alignment condition for basic type is as follows.

If the -Xinline_strcpy option of the CC-RH is specified, however, all the arrey types are 4-byte boundaries.

Table 4.11

Alignment Condition for Basic Type

Basic Type

Alignment Conditions

(unsigned) char and its array type

_Bool type

Byte boundary

(unsigned) short and its array type

2-byte boundary

Other basic types (including pointer)

(unsigned) long long and its array type

double and its array type

4-byte boundary

long double and its array type

4-byte boundary

(b)

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.

 

Here are examples of the respective cases:

Example 1.

union  tug1 {
  unsigned short i; /*2 bytes member*/
  unsigned char  c; /*1 bytes member*/
};  /*The union is aligned with 2-byte.*/

Example 2.

union  tug2 {
  unsigned int  i;  /*4 bytes member*/
  unsigned char  c; /*1 byte member*/
};  /*The union is aligned with 4-byte.*/

(c)

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.

 

Here are examples of the respective cases:

Example 1.

struct  ST {
        char    c;      /*1 byte member*/
};  /*Structure is aligned with 1-byte.*/

Example 2.

struct  ST {
        char    c;      /*1 byte member*/
        short   s;      /*2 bytes member*/
};  /*Structure is aligned with 2-byte.*/

Example 3.

struct  ST {
        char    c;      /*1 byte member*/
        short   s;      /*2 bytes member*/
        short   s2;     /*2 bytes member*/
};  /*Structure is aligned with 2-byte.*/

Example 4.

struct  ST {
        char    c;      /*1 byte member*/
        short   s;      /*2 bytes member*/
        int     i;      /*4 bytes member*/
};  /*Structure is aligned with 4-byte.*/

Example 5.

struct  ST {
        char        c;      /*1 byte member*/
        short       s;      /*2 bytes member*/
        int         i;      /*4 bytes member*/
        long long   ll;     /*4 bytes member*/
};  /*Structure is aligned with 4-byte.*/

(d)

Alignment condition for function argument

The alignment condition for a function argument is a 4-byte boundary.

(e)

Alignment condition for executable program

The alignment condition when an executable object module file is created by linking object files is 2-byte boundary.