ALIGNED specifies that the data element is aligned on the storage boundary corresponding to its data-type requirement. UNALIGNED specifies that each data element is mapped on the next byte boundary, except for fixed-length bit strings, which are mapped on the next bit.
|
Defaults are applied at element level. UNALIGNED is the default for bit data, character data, graphic data, widechar data and numeric character data. ALIGNED is the default for all other types of data.
Requirements for the ALIGNED attribute are shown in Table 26.
| Variable Type | Stored Internally as: | Storage Requirements (Bytes) | Alignment Requirements | |
|---|---|---|---|---|
| ALIGNED Data | UNALIGNEDData | |||
|
Note:
Alignment and storage requirements for program control data can vary across supported systems. Complex data requires twice as much storage as its real counterpart, but the alignment requirements are the same. |
||||
| BIT (n) | ALIGNED:One byte for each group
of 8 bits (or part thereof)
UNALIGNED: As many bits as are required, regardless of byte boundaries |
ALIGNED: CEIL(n/8)
UNALIGNED: n bits |
Byte(Data can begin on any byte, 0 through 7) | Bit(Data can begin on any bit in any byte, 0 through 7) |
| CHARACTER (n) | One byte per character | n | Byte(Data can begin on any byte, 0 through 7) | Byte(Data can begin on any byte, 0 through 7) |
| CHARACTER (n)VARYINGZ | One byte per character plusone byte for the nullterminator | n+1 | ||
| GRAPHIC (n) | Two bytes per graphic | 2n | ||
| GRAPHIC (n) VARYINGZ | Two bytes per graphic plustwo bytes for the nullterminator | 2n+2 | ||
| WIDECHAR (n) | Two bytes per widechar. | 2n | ||
| WIDECHAR (n)VARYINGZ | Two bytes per widechar plustwo bytes for the nullterminator | 2n+2 | ||
| PICTURE | One byte for each PICTURE character (except V, K, and the F scaling factor specification) | Number of PICTURE characters other than V, K, and F specification | ||
| DECIMAL FIXED (p,q) | Packed decimal format (1/2 byte per digit, plus 1/2 byte for sign) | CEIL((p+1)/2 | ||
| BINARY FIXED(p,q)
SIGNED 1 <= p <= 7 UNSIGNED 1 <= p <= 8 |
One byte | 1 | ||
| ORDINAL
SIGNED 1 <= p <= 7 UNSIGNED 1 <= p <= 8 |
||||
| BIT(n) VARYING | Two-byte prefix plus 1 byte for each group of 8 bits (or part thereof) of the declared maximum length | ALIGNED:2+CEIL(n/8)
UNALIGNED: 2 bytes+n bits |
Halfword (Data can begin on byte 0, 2, 4, or 6) | Byte(Data can begin on any byte, 0 through 7) |
| CHARACTER(n) VARYING | Two-byte prefix plus 1 byte per character of the declared maximum length | n+2 | ||
| GRAPHIC(n) VARYING | Two-byte prefix plus 2 bytes per graphic of the declared maximum length | 2n+2 | ||
| WIDECHAR(n) VARYING | Two-byte prefix plus 2 bytes per widechar of the declared maximum length | 2n+2 | ||
| BINARY FIXED(p,q)
SIGNED 8 <= p <= 15 UNSIGNED 9 <= p <= 16 |
Halfword | 2 | ||
| ORDINAL
SIGNED 8 <= p <= 15 UNSIGNED 9 <= p <= 16 |
||||
| BINARY FIXED(p,q)
SIGNED 16 <= p <= 31 UNSIGNED 17 <= p <= 32 |
Fullword | 4 | Fullword (Data can begin on byte 0 or 4) | Byte(Data can begin on any byte, 0 through 7) |
| ORDINAL
SIGNED 16 <= p <= 31 UNSIGNED 17 <= p <= 32 |
||||
| BINARY FLOAT(p)1<=p<=21 | Short floating-point | |||
| DECIMAL FLOAT(p) 1<=p<=6 if not DFP | ||||
| DECIMAL FLOAT(p) 1<=p<=7 if DFP | ||||
| POINTER | - | 4 | Fullword(Data can begin on byte 0 or 4) | Byte(Data can begin on any byte, 0 through 7) |
| HANDLE | - | |||
| OFFSET | - | |||
| FILE | - | |||
| ENTRY LIMITED | - | |||
| ENTRY | - | 8 | ||
| LABEL or FORMAT | - | |||
| TASK | - | 16 | ||
| AREA | - | 16+size | Doubleword (Data can begin on byte 0) | AREA data cannot be unaligned |
| BINARY FIXED(p,q)
SIGNED 32 <= p <= 63 UNSIGNED 33 <= p <= 64 |
- | 8 | byte(Data can begin on any byte, 0 through 7) | |
|
BINARY FLOAT(p) 22 <= p <= 53 |
Long floating-point | |||
| DECIMAL FLOAT(p) 8<=p<=16 if not DFP | ||||
| DECIMAL FLOAT(p) 7<=p<=16 if DFP | ||||
|
BINARY FLOAT(p) 54 <= p |
Extended floating-point | 16 | ||
| DECIMAL FLOAT(p) 17<=p | ||||
ALIGNED or UNALIGNED can be specified for element, array, structure, or union variables. The application of either attribute to a structure or union is equivalent to applying the attribute to all contained elements that are not explicitly declared ALIGNED or UNALIGNED.
The following example illustrates the effect of ALIGNED and UNALIGNED declarations for a structure and its elements:
declare 1 S,
2 X bit(2), /* unaligned by default */
2 A aligned, /* aligned explicitly */
3 B, /* aligned from A */
3 C unaligned, /* unaligned explicitly */
4 D, /* unaligned from C */
4 E aligned, /* aligned explicitly */
4 F, /* unaligned from C */
3 G, /* aligned from A */
2 H; /* aligned by default */
For more information about structures and unions, refer to Structures and Unions.