C/C++ Programmer's Guide (G06.25+)
Compiler Pragmas
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
13-32
FIELDALIGN
•
SHARED8 requires that you explicitly declare any filler needed to properly align
fields. The compiler issues a warning for improperly aligned fields in a SHARED8
structure.
•
For more details on structure alignment, refer the pTAL Conversion Guide and
pTAL Reference Manual.
•
When a 64-bit unsigned value is defined in a structure, class, or union that has
been qualified with FIELDALIGN SHARED2 or FIELDALIGN SHARED8, the
compiler issues a warning because compilation might fail on another platform.
•
For TNS C++, there are additional restrictions:
°
FIELDALIGN must be AUTO for inherited classes and their base classes and
classes with virtual member functions.
°
Templates cannot be specified in FIELDALIGN pragmas and always have
FIELDALIGN AUTO. Nested structs are not implemented for templates.
Templates can contain non-AUTO structs declared using tags.
°
No other pragmas can appear on the same source line as #pragma
FIELDALIGN.
Examples
1. Global pragma FIELDALIGN is allowed anywhere in the source, not just at the
beginning, and it can also be used as an argument to pragmas PUSH and POP.
For example:
#pragma fieldalign auto
// the global fieldalign is now set to auto
struct AutoStruct {};
#pragma push fieldalign
//save the current fieldalign value
#pragma fieldalign shared2
// the global fieldalign is now shared2In t
struct Shared2Struct{};
#pragma pop fieldalign
//global fieldalign is restored to auto
2. In the following example, the member str1.str2.c2 starts at a byte address
instead of the typical 16-bit word address:
#pragma fieldalign shared2 STAG
struct STAG { char c1;
struct { char c2;
int i;
} str2; /* substructure declared
inline without tag */
} str1;