Search | | Contact Us | Resource Center Login | Home|

Given the following function:

function total, ^val, varargs
	arg	,int
	sum	,int
	clear sum
	for arg from 1 thru %numargs
	  sum += ^argn(arg)
	freturn sum

what is the return value if the function is called like so:


At what position in the data structure does the field "x" referenced in the window begin?

a. 1
b. 3
c. 6
d. a runtime error


The function treats all of its arguments as numeric parameters and adds them together to return their sum. In this case, the third argument is not passed. Contrary to what its name implies, the %NUMARGS function does not return the number of arguments passed but rather the position of the last argument, which would be 4 in this example. However, because the third argument is not passed, attempting to access it via ^ARGN causes an "Argument missing" error. Therefore, (d) is the correct answer.

To make this function ignore embedded unpassed arguments, insert the statement

if (^passed(^arg(arg)))

between the FOR statement and the addition operation.

More information about News and Events

Contact Synergex to learn more about  News and Events