A variable-length list of arguments in Perl XS

The following example XS program demonstrates the use of a list of arguments of variable length in Perl XS.

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

MODULE=VLenArg PACKAGE=VLenArg

PROTOTYPES: ENABLE

void
testit (word, ...)
        SV * word;
CODE:
        if (items > 1) {
                int i;
                for (i = 1; i < items; i++) {
                        SV * x;
                        char * pv;
                        int len;
                        x = ST(i);
                        pv = SvPV (x, len);
                        printf ("Argument %d: %s:%d\n", i, pv, len);
                }
        }

(download)


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer