About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/__pop_args.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 __pop_args Context: slangrtl

Synopsis

Remove n function arguments from the stack

Syntax

variable args = __pop_args(Integer_Type n);

Description

This function together with the companion function __push_args is useful for passing the arguments of a function to another function. __pop_args returns an array of n structures with a single structure field called value, which represents the value of the argument.

Example

Consider the following print function. It prints all its arguments to stdout separated by spaces:

    define print ()
    {
       variable i;
       variable args = __pop_args (_NARGS);

       for (i = 0; i < _NARGS; i++)
         {
            () = fputs (string (args[i].value), stdout);
            () = fputs (" ", stdout);
         }
       () = fputs ("\n", stdout);
       () = fflush (stdout);
    }

Now consider the problem of defining a function called ones that returns a multi-dimensional array with all the elements set to 1. For example, ones(10) should return a 1-d array of ones, whereas ones(10,20) should return a 10x20 array.

    define ones ()
    {
      !if (_NARGS) return 1;
      variable a;

      a = __pop_args (_NARGS);
      return @Array_Type (Integer_Type, [__push_args (a)]) + 1;
    }

Here, __push_args was used to push on the arguments passed to the ones function onto the stack to be used when dereferencing Array_Type.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.