ILE C/C++ Programmer's Guide

Source Code Samples

Figure 194. T1520DL8 -- ILE C Source that Uses OS/400 pointers




/* This program passes several types of OS/400 pointers as arguments */
/* to another ILE C program T1520DL9. */
#include <stdio.h>
#include <pointer.h>
#pragma(p128)
typedef struct {
_SPCPTR spcptr; /* A space pointer. */
_SYSPTR sysptr; /* A system pointer. */
void (*fnptr)(); /* A function pointer. */
} PtrStructure;
#pragma linkage (T1520DL9, OS)


#pragma datamodel(pop)
void T1520DL9 (PtrStructure *, _SPCPTR, _SYSPTR, void (*)());
void function1(void) /* A function definition. */
{
printf("Hello!\n");
}

int main(void)
{
int i = 4;
PtrStructure ptr_struct;
/* Make assignments to the fields of ptr_struct. */
ptr_struct.spcptr = (_SPCPTR)&i; /* A space pointer. */
ptr_struct.sysptr = (_SYSPTR)T1520DL9; /* A system pointer. */
ptr_struct.fnptr = &function1; /* A function pointer. */

/* Call T1520DL9, passing the address of ptr_struct and other */
/* valid OS/400 pointer arguments. */

T1520DL9(&ptr_struct, (_SPCPTR)&i, (_SYSPTR)T1520DL9, &function1);
}

Figure 195. T1520DL9 -- ILE C Source that Uses OS/400 pointers




/* This program receives the arguments from T1520DL8 and checks them */
/* to make sure they were passed correctly. */
#include <stdio.h>
#include <pointer.h>
typedef struct {
_SPCPTR spcptr; /* A space pointer. */
_SYSPTR sysptr; /* A system pointer. */
void (*fnptr)(); /* A function pointer. */
} PtrStructure;
int main( int argc, char **argv)
{
_OPENPTR openptr; /* An open pointer. */
_SPCPTR spcptr; /* A space pointer. */
_SYSPTR sysptr; /* A system pointer. */
void (*fnptr)(); /* A function pointer. */
PtrStructure *ptr_struct_ptr;
int error_count = 0;
/* Receive the structure pointer passed into a local variable. */
ptr_struct_ptr = (PtrStructure *)argv[1];



/* Receive the OS/400 pointers passed into an open pointer, */
/* then assign them to pointers of their own type. */
openptr = (_OPENPTR)argv[2];
spcptr = openptr; /* A space pointer. */

openptr = (_OPENPTR)argv[3];
sysptr = openptr; /* A system pointer. */

openptr = (_OPENPTR)argv[4];
fnptr = openptr; /* A function pointer. */

/* Test the pointers passed with the pointers in ptr_struct_ptr. */

if (spcptr != ptr_struct_ptr->spcptr)
++error_count;
if (sysptr != ptr_struct_ptr->sysptr)
++error_count;
if (fnptr != ptr_struct_ptr->fnptr)
++error_count;

if (error_count > 0)
printf("Pointers not passed correctly.\n");
else
printf("Pointers passed correctly.\n");
return;
}


[ Top of Page | Previous Page | Next Page | Table of Contents ]