3.8 Variable-Length Argument Lists in System Services

Most system services and other external procedures require a specific number of arguments, but some accept a variable number of optional arguments. Because DEC C function declarations do not show the number of parameters expected by external functions unless a function prototype is used, the way you call an external function from a DEC C program depends on the semantics of the called function. You must supply the number of arguments that the external function expects. The rules are as follows:

For example, the function STR$CONCAT, in the Common Run-Time Library, concatenates from 2 to 254 strings into a single string. It has the following call format:

ret = STR$CONCAT(dst, src1, src2[,
src3, . . . src254]);

For more information about the STR$CONCAT function, see the VMS Run-Time Library Routines Volume.

The identifier dst is the destination for the concatenated string, and src1, src2, . . . src254 are the source strings. All arguments are passed by descriptor. All but the first two source strings are optional. The function checks to see how many arguments are present in the call; if fewer than three (the destination and two sources) are present, the function returns an error status value. Example 3-20 shows a call to the STR$CONCAT function from DEC C.

Example 3-20 Using Variable-Length Argument Lists

/*  This example shows a call to STR$CONCAT.                   */

#include <stdio.h>
#include <descrip.h>
#include <ssdef.h>

int STR$CONCAT();

int main(void)
{
   int ret;                        /*  Return status of        *
                                    *   STR$CONCAT             */

                                   /*  Destination array of    *
                                    *   concatenated strings   */
   char dest[21];

                                   /*  Create compile-time     *
                                    *   descriptors:           */
          $DESCRIPTOR(dst, dest);
   static $DESCRIPTOR(src1, "abcdefghij");
   static $DESCRIPTOR(src2, "klmnopqrst");

                                   /*  Concatenate strings     */
   ret =  STR$CONCAT(&dst, &src1, &src2);

                                   /* Test return status value */
   if (ret != SS$_NORMAL)
      fprintf(stderr,"Failed to concatenate strings.\n"),
      exit(ret);

                                   /*  Process string          */
   else
        dest[20] = '\0',
        printf("Resultant string: %s\n",dest);
}


Previous Page | Next Page | Table of Contents | Index