*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> ftn/varargs (3)              


VARARGS(3F)							   VARARGS(3F)

NAME    [Toc]    [Back]

     varargs, argmnt, getadr, nullok, xetarg, retour - allow variable number
     of	arguments in argument list

SYNOPSIS    [Toc]    [Back]

     subroutine	argmnt(	nargs )
     integer*4 nargs

     subroutine	getadr(	n, iaddr )
     integer*4 n, iaddr

     integer*4 function	nullok(	n, iaddr )
     integer*4 n, iaddr

     subroutine	xetarg(	n, len,	iarg )
     integer*4 n, len
     anytype iarg

     subroutine	retour(	nargs, len1, val1, len2, val2, ..., lenn, valn )
     integer*4 nargs, len1, len2, ..., lenn
     anytype val1, val2, ..., valn

DESCRIPTION    [Toc]    [Back]

     These utilities are used to provide f77 support for subroutines with
     variable number of	arguments.  In order to	use these utilities, all
     variable argument subroutines must	be declared in each source file	before
     they are referenced or defined.   This is done by adding a	$varargs
     compiler directive	at the beginning of the	source file.

     For example:

     $varargs vasub1 vasub2 vasub3

     where vasub1, vasub2, and vasub3 are the names of the variable argument
     subroutines which are referenced or defined in the	current	source file.

     argmnt returns the	number of actual arguments in the integer variable
     nargs.  The default behavior is to	count each character argument in the
     actual argument list as two arguments since both the character address
     and its length will be put	on the argument	stack.	The -chararg1 option
     can be used to count each character argument as only one argument.

     getadr returns the	address	of the nth argument in the variable iaddr.
     This function has to be used to get the length of a character argument
     since it is passed	by value, not by reference like	other Fortran

     nullok returns 0 if the address of	the nth	argument is the	same as	the
     address contained in the variable iaddr.

									Page 1

VARARGS(3F)							   VARARGS(3F)

     xetarg initializes	len bytes of iarg with the value of the	nth argument .

     retour returns values to the calling program by setting nargs actual
     arguments using len1, len2,..., lenn bytes	of the values stored in	the
     variables val1, val2,..., valn, respectively.

     In	normal usage of	variable argument subroutines, when the	formal
     argument list is specified	using the maximum number of arguments the
     subroutine	can received, the argument addresses and return	values are
     passed in the standard f77	convention.  The only utility needed in	this
     case is argmnt to determine the number of actual arguments	passed to the
     variable argument subroutine.

     The other utilities are needed when there is no formal argument list in
     the variable argument subroutine. xetarg is normally used to initializes
     some local	variables to the initial values	of the actual arguments.
     retour is then used to return the locally calculated values back to the
     calling subroutine	by setting the actual arguments	to the values of the
     local variables.


     $varargs chsign
	  program tvararg
	  i = 1
	  j = -2
	  k = 3
	  call chsign( i, j, k,	"fourth	argument", "fifth" )
	  print	*, i, j, k

	  subroutine chsign()
     C	  This subroutine changes the sign of all integer arguments passed to it
     C	  and prints the value of all character	arguments.  It assumes that
     C	  there	are at most three integer arguments, followed by the character
     C	  arguments.  The way this subroutine is written it has	to be compiled
     C	  with the -chararg1 option since it assumes that the lengths of the
     C	  character arguments can be obtained by using GETADR(NARGS+I) where
     C	  NARGS	is the number of arguments returned by ARGMNT().
	  integer*4 val(3)
	  pointer (stradr, str)
	  character*(*)	str

	  call argmnt( nargs )
	  print	*, "Number of arguments	= ", nargs
	  j = min(3,nargs)
	  do 10	i=1,j
	      call xetarg( i, 4, val(i)	)
     10	  val(i) = - val(i)
     C	  Get the address and the length of the	character arguments
	     do	100 i=j+1, nargs
		 call getadr( i, stradr	)

									Page 2

VARARGS(3F)							   VARARGS(3F)

		 call getadr( nargs+i-j, lenstr	)
		 write (*,*) str(1:lenstr)
     100     continue

	  call retour(j,4,val(1),4,val(2),4,val(3))

									PPPPaaaaggggeeee 3333
[ Back ]
 Similar pages
Name OS Title
varargs IRIX variable argument list
stdarg IRIX variable argument list
varargs HP-UX handle variable argument list
vprintf IRIX print formatted output of a variable argument list
varargs FreeBSD variable argument lists
stdarg Linux variable argument lists
stdarg NetBSD variable argument lists
varargs NetBSD variable argument lists
va_arg NetBSD variable argument lists
va_copy NetBSD variable argument lists
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service