Common API programming errors
This topic contains information about common API programming errors and provides correct and incorrect program examples.
Note: Do not assume that an API can do things other than what
the API documentation states. If the API documentation does not state specifically
that something is allowed, it probably is not.
- Using the error code parameter
The error code parameter provides a way for you to determine whether an API encounters any errors. Here are the program examples that show the incorrect and correct ways of using the error code parameter. - Defining data structures
When a data structure is defined for use with an API, the structure must be built to receive what the API returns. Here are the program examples that show the incorrect and correct ways of defining data structures. You can prevent errors by using IBM-supplied data structures rather than creating your own data structures. - Defining receiver variables
When you define a receiver variable, the most common error is to create a receiver variable that is too small for the amount of data that it is to receive. Here are the program examples that show the incorrect and correct ways of defining receiver variables. - Defining list-entry format lengths
When you define the list-entry format length, the most common error is to statically encode the format length in your program. Here are the program examples that show the incorrect and correct ways of defining list-entry format lengths. - Using null pointers with program-based APIs
Many programmers, especially those with a C programming background, view ignored parameters and NULL parameters as being the same. This expectation can lead to unexpected results when program-based APIs are used. Here are the program examples that show the incorrect and correct ways of using null pointers with program-based APIs. - Defining byte alignment
Correct byte alignment ensures that an API reads the data from the beginning of a record rather than at some other point. Here are the program examples that show the incorrect and correct ways of defining byte alignment. - Using offsets in a user space
An offset indicates the point in a data structure where specific data should start. If you use offsets correctly, your program can extract specific pieces of data from the structure. Here are the program examples that show the incorrect and correct ways of using offsets. - Coding for new functions
A new function from IBM can cause programs to fail if the programs do not allow for the handling of this function. Here are the program examples that show the incorrect and correct ways of using a new function.
Parent topic: Application programming interfaces