Previous: C Calling Sequence Up: C Calling Sequence Next: C Data Types

Differences from Fortran

There are several differences in the C calling sequence from the Fortran calling sequence. The name change has been discussed already. Also, the use of a 0 or NULL terminator for a keyword-value argument list has been discussed above. There are two major differences that will come up in porting programs, however. They both have to do with making the interface conform to standard C calling conventions.

First, most arguments are now passed by value. The old RTL routines expected all arguments to be passed by reference, since that's how Fortran does it. This leads to all sorts of strange constructs like ``&1'' in C, which is not valid on most machines. The rule is: if it's an input value, it's passed by value. If it's an output value, it of course must still be passed by reference (as a pointer). For example, ``unit'' is a parameter to most of the RTL routines. Instead of calling zvread(&unit, ...);, you call zvread(unit, ...); (where ``unit'' is an integer). The routine zvunit, however, returns ``unit'' as an output, so it would still have to be called ``zvunit(&unit, ...);''. Most values in keyword-value pairs are input, so the ``&''s would go away. On zvget, however, most values are output, so they are still passed as pointers. Arrays of items, as well as strings, are still passed by reference as per standard C practice. It sounds rather confusing, but it makes sense once you work with it a little.

There is a pitfall to be aware of regarding zladd. Since zladd accepts as input the value to which to set the label, you might expect it to be passed by value. However, zladd can accept arrays of items, since a label may be multi-valued. Therefore, the ``value'' parameter to zladd is always passed by reference. This can be confusing if only one value is being added. This is not an issue with zlget, since ``value'' is an output from zlget. You would expect ``value'' to be passed by reference in that case.

Second, many routines had a ``status'' argument, which returned the status of the command. These arguments have been removed. The status is now the return value of the function. So, instead of ``zvread(unit,&status,...);'', it is now ``status = zvread(unit,...);''. If you don't need the status value, it can be ignored entirely, as in ``zvread(unit,...);''.

Also, the handling of arrays of strings as arguments has been improved and made consistent in the C interface. Only a few routines use string arrays as arguments, but the calls to those routines should be examined carefully. These routines are zladd, zlget, zlhinfo, zvpout, zvparm, zviparm, zvparmd, and zviparmd. See below for the rules on passing string arrays.