Using

Null

Pointers

with

OPM

APIs

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Many

programmers, especially those with a C programming

background,

view

 

 

 

ignored

parameters and NULL

parameters

as

being

the

same. This

expecta

 

 

can

 

lead to unexpected results when OPM-based

APIs are

used.

 

 

 

 

 

Note:

Using

NULL

with

ignored

parameters

is primarily

a

consideration

wi

 

 

 

 

OPM-based APIs. ILE-based APIs allow you to pass NULL parameters t

 

 

 

 

indicate omitted

parameter

values.

 

 

 

 

 

 

 

 

 

 

 

 

Even

though

the

value

assigned

to

a

parameter

is

not

used,

the

parame

 

 

must

be addressable. When you use NULL for a parameter value, the s

 

 

ceptually passes an address that can be equated with 0, where

0

ind

 

 

parameter cannot be addressed. This

lack

of

addressability

often resu

 

 

tion

check (MCH3601). Additionally, other error messages

may also

occur.

Using

Null

Pointers

with

OPM

APIs—Example

of

Incorrect

Coding

 

 

 

 

 

 

 

 

 

The following program has two parameter values coded as NULL. They are ignored parameters of the member and record format used in the List Relations (QDBLDBR) API, which is .shown12/ onatpage 9-19. The correct

coding is shown.13/at on page 9-21.

When the program is called, a machine function check of MCH3601 is repo because the address of the required parameters member and record specified as NULL.

/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/

/\

 

 

 

\/

/\Program Name: PGM1

 

 

\/

/\

 

 

 

\/

/\Program Language:

ILE

C

\/

/\

 

 

 

\/

/\Description: This sample program illustrates the incorr￿ect

\/

/\

use of ignored and null parameters.

\/

/\

 

 

 

\/

/\Header Files Included: <stdio.h>

\/

/\

 

 

<qusec.h>

\/

/\

 

 

<qusgen.h>

\/

/\

 

 

<qdbldbr.h>

\/

/\

 

 

<quscrtus.h>

\/

/\

 

 

<qusptrus.h>

\/

/\

 

 

<qliept.h>

\/

/\

 

 

 

\/

/\APIs Used:

QUSCRTUS -

Create User Space

\/

/\

QDBLDBR

-

List Database Relations

\/

/\

QUSPTRUS -

Retrieve Pointer to User Space

\/

/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/ #include <stdio.h>

#include <qusec.h> #include <qusgen.h> #include <qdbldbr.h> #include <quscrtus.h> #include <qusptrus.h> #include <qliept.h> main()

{

9-18System API Programming V4R1

Page 224
Image 224
IBM Version 4 manual Null, Ile