IBM Version 4 Universal Remote User Manual


 
Defining Byte Alignment
Correct byte alignment ensures that data used with an API is correct. Byte align-
ment is also essential when APIs are used to retrieve and then print or display
data. When byte alignment is off, it causes the API to read the data at some point
other than at the beginning of a record.
Defining Byte Alignment—Example of Incorrect Coding
This program illustrates byte alignment while defining a structure. This is shown at
14 on page 9-23. Four-byte alignment is required when using this program.
Variable-length records must begin on a 4-byte boundary. As shown at 14, the
variable-length record CCSID_rec is not beginning on a 4-byte boundary. When
the API accesses the CCSID_rec record, 4-byte alignment is forced by padding the
first 3 bytes of the CCSID_rec between the replace field and the start of the
CCSID_rec record. 15 on page 9-24 shows that the variable-length record is
not 4-byte aligned (the value is 13, which is not divisible by 4). The correct coding
is shown at 17 on page 9-26.
Note: Not all APIs require a 4-byte boundary. ILE APIs, such as
QusAddExitProgram, do.
/ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ ᑍ/
/ᑍ ᑍ/
/ᑍProgram Name: PGM1 ᑍ/
/ᑍ ᑍ/
/ᑍProgram Language: ILE C ᑍ/
/ᑍ ᑍ/
/ᑍDescription: This program illustrates improper byte ᑍ/
/ᑍ alignment when using variable length ᑍ/
/ᑍ records. ᑍ/
/ᑍ ᑍ/
/ᑍ ᑍ/
/ᑍHeader Files Included: <stdio.h> ᑍ/
/ᑍ <signal.h> ᑍ/
/ᑍ <string.h> ᑍ/
/ᑍ <stdlib.h> ᑍ/
/ᑍ <qusrgfa1.h> ᑍ/
/ᑍ <qusec.h> ᑍ/
/ᑍ <qliept.h> ᑍ/
/ᑍ ᑍ/
/ᑍ APIs Used: QusAddExitProgram - Add an exit program ᑍ/
/ᑍ ᑍ/
/ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ/
/ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ/
/ᑍ Includes ᑍ/
/ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <qusrgfa1.h>
#include <qusec.h>
#include <qliept.h>
/ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ/
/ᑍ Structures ᑍ/
9-22 System API Programming V4R1