Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Programming Guide

Matching string parameter types

Now that we have translated fread correctly, we might try this translation for fopen:

Figure 69. First incorrect declaration of fopen
  dcl fopen    ext('fopen')
               entry( char(*) varyingz byvalue,
                      char(*) varyingz byvalue )
               returns( byvalue type file_handle );

But C really has no strings, only pointers, and these pointers would be passed byvalue; so the strings should be byaddr:

Figure 70. Second incorrect declaration of fopen
  dcl fopen    ext('fopen')
               entry( char(*) varyingz byaddr,
                      char(*) varyingz byaddr )
               returns( byvalue type file_handle );

But PL/I passes descriptors with strings and C doesn't understand them, so they must be suppressed. We can do this by adding options(nodescriptor) to the declaration:

Figure 71. Correct declaration of fopen
  dcl fopen    ext('fopen')
               entry( char(*) varyingz byaddr,
                      char(*) varyingz byaddr )
               returns( byvalue type file_handle )
               options ( nodescriptor );

This will work, but isn't optimal since the parameters are input-only; if the parameter is a constant, the nonassignable attribute will prevent a copy being made and passed. Hence, the best translation of the declaration of fopen is:

Figure 72. Optimal, correct declaration of fopen
  dcl fopen    ext('fopen')
               entry( char(*) varyingz nonasgn byaddr,
                      char(*) varyingz nonasgn byaddr )
               returns( byvalue type file_handle )
               options ( nodescriptor );

At this point, the declare for the fclose function presents few surprises except perhaps for the optional attribute in the returns specification. This attribute allows us to invoke the fclose function via a CALL statement and not have to dispose of the return code. But please note that if the file were an output file, the return code on fclose should always be checked since the last buffer may be written out only when the file is closed and that write could fail for lack of space.

Figure 73. Declaration of fclose
  dcl fclose   ext('fclose')
               entry( type file_handle byvalue )
               returns( optional type int byvalue )
               options ( nodescriptor );

Now, on z/OS UNIX, we can compile and run the programs with the commands:

Figure 74. Commands to compile and run filedump
     pli -qdisplay=std filedump.pli

     filedump filedump.pli

This would produce the following output:

Figure 75. Output of running filedump
    15408689 938584A4 94977A40 97999683  . filedump: proc
    4D86955D 409697A3 899695A2 4D959685  (fn) options(noe
    A7858396 97A24094 8189955D 5E151540  xecops main);..

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)