Download PGI Compiler Reference Manual
Transcript
C and C++ Data Types Data Type Alignment on this size boundary long long [int] 8-byte boundary, signed or unsigned. C and C++ Aggregate Data Types An aggregate data type consists of one or more scalar data type objects. You can declare the following aggregate data types: array consists of one or more elements of a single data type placed in contiguous locations from first to last. class (C++ only) is a class that defines an object and its member functions. The object can contain fundamental data types or other aggregates including other classes. The class members are allocated in the order they appear in the definition but may not occupy contiguous locations. struct is a structure that can contain different data types. The members are allocated in the order they appear in the definition but may not occupy contiguous locations. When a struct is defined with member functions, its alignment rules are the same as those for a class. union is a single location that can contain any of a specified set of scalar or aggregate data types. A union can have only one value at a time. The data type of the union member to which data is assigned determines the data type of the union after that assignment. Class and Object Data Layout Class and structure objects with no virtual entities and with no base classes, that is just direct data field members, are laid out in the same manner as C structures. The following section describes the alignment and size of these C-like structures. C++ classes (and structures as a special case of a class) are more difficult to describe. Their alignment and size is determined by compiler generated fields in addition to user-specified fields. The following paragraphs describe how storage is laid out for more general classes. The user is warned that the alignment and size of a class (or structure) is dependent on the existence and placement of direct and virtual base classes and of virtual function information. The information that follows is for informational purposes only, reflects the current implementation, and is subject to change. Do not make assumptions about the layout of complex classes or structures. All classes are laid out in the same general way, using the following pattern (in the sequence indicated): • First, storage for all of the direct base classes (which implicitly includes storage for non-virtual indirect base classes as well): • When the direct base class is also virtual, only enough space is set aside for a pointer to the actual storage, which appears later. • In the case of a non-virtual direct base class, enough storage is set aside for its own non-virtual base classes, its virtual base class pointers, its own fields, and its virtual function information, but no space is allocated for its virtual base classes. 6