Using the IFS APIs -- Part 1: Introduction -- Follow-up

Article ID: 16961

We received the following letter from IBM Toronto Lab's Barbara Morris regarding the first tip of this series, which ran in the June 26 newsletter:

> Character variables are passed as pointers to C strings. A
> C string is null-terminated, that is, it ends with a hex '00'.
> In RPG, you use the %addr to return a pointer to a variable.
> So the open code now looks like this:
>
>   path = %trim( name ) + x'00';
>   handle = open( %addr( path ) );

RPG has had support for passing null-terminated strings since V3R7. It was added specifically for cases just like the open API. To use it, you just code OPTIONS(*STRING) on the pointer parameter. This lets you pass a character expression for the pointer parameter; the compiler will create a temporary with the character expression followed by x'00' and pass the address of the temporary.

D open           pr         extproc('open')
D   filename             *  options(*string)

           ptr = open(%trim(name));

Thanks to Barbara for the above clarification. We've made the changes to the STMIOH.RP4 file incorporating the options(*string) code.

Look for Part 2 of this series in next week's newsletter.

ProVIP Sponsors

ProVIP Sponsors