C and C++ Data Types
The offset of a structure member from the beginning of the structure is a multiple of the member’s alignment.
For example, since an INTEGER*2 aligns on a 2-byte boundary, the offset of an INTEGER*2 member from the beginning of a structure is a multiple of two bytes.
Fortran 90 Aggregate Data Types (Derived Types)
The Fortran 90 standard added formal support for aggregate data types. The TYPE statement begins a derived type data specification or declares variables of a specified user-defined type. For example, the following would define a derived type ATTENDEE:
TYPE ATTENDEE
CHARACTER(LEN=30) NAME
CHARACTER(LEN=30) ORGANIZATION
CHARACTER (LEN=30) EMAIL
END TYPE ATTENDEE
In order to declare a variable of type ATTENDEE and access the contents of such a variable, code such as the following would be used:
TYPE (ATTENDEE) ATTLIST(100)
. . .
ATTLIST(1)%NAME = ‘JOHN DOE’
C and C++ Data Types
C and C++ Scalars
Table 15.4, “C/C++ Scalar Data Types”
lists C and C++ scalar data types, providing their size and format.
The alignment of a scalar data type is equal to its size. Table 15.5, “Scalar Alignment,” on page 195
shows scalar alignments that apply to individual scalars and to scalars that are elements of an array or members of a structure or union. Wide characters are supported (character constants prefixed with an L). The size of each wide character is 4 bytes.
Data Type
unsigned char
[signed] char unsigned short
[signed] short unsigned int
[signed] int
[signed] long [int] (32-bit operating systems and win64)
4
[signed] long [int]
(linux86-64 and sua64)
8
2
4
4
1
1
2
Table 15.4. C/C++ Scalar Data Types
Size
(bytes)
Format
ordinal ordinal
Range
0 to 255
2's complement integer -128 to 127
0 to 65535
2's complement integer -32768 to 32767 ordinal 0 to 2
32
-1
2's complement integer -2
31
to 2
31
-1
2's complement integer -2
31
to 2
31
-1
2's complement integer -2
63
to 2
63
-1
194
Chapter 15. Fortran, C, and C++ Data Types
Data Type
unsigned long [int] (32-bit operating systems and win64) unsigned long [int]
(linux86-64 and sua64)
[signed] long long [int]
Size
(bytes)
4
8
8 unsigned long long [int] float
8
4 double long double bit field
(2)
(unsigned value) 1 to 32 bit field
(2) pointer enum
(signed value)
8
8 bits
1 to 32 bits
4
4
Format
ordinal ordinal
Range
0 to 2
0 to 2
32
64
-1
-1
2's complement integer -2
63
to 2
63
-1 ordinal 0 to 2
64
-1
IEEE single-precision floating-point
10
-37
to 10
38
(1)
IEEE double-precision floating-point
10
-307
to 10
308
(1)
IEEE double-precision floating-point
10
-307
to 10
308 (1) ordinal 0 to 2 size
-1, where size is the number of bits in the bit field
2's complement integer -2 size-1
to 2 size-1
-1, where size is the number of bits in the bit field address 0 to 2
32
-1
2's complement integer -2
31
to 2
31
-1
(1)
Approximate value
(2)
Bit fields occupy as many bits as you assign them, up to 4 bytes, and their length need not be a multiple of 8 bits (1 byte)
Table 15.5. Scalar Alignment
Data Type
char short int enum pointer float double long double long [int] 32-bit on Win64 long [int] linux86-64, sua64
Alignment on this size boundary
1-byte boundary, signed or unsigned.
2-byte boundary, signed or unsigned.
4-byte boundary, signed or unsigned.
4-byte boundary.
4-byte boundary.
4-byte boundary.
8-byte boundary.
8-byte boundary.
4-byte boundary, signed or unsigned.
8-byte boundary, signed or unsigned.
195