Okay, so creating a var-arg array is impossible, but I had the K&R book and
the Inline::C-Cookbook both open, so I got a good start on showing how the
minprintf function could be done with Inline::C.
--Eric
--
#!/usr/bin/perl
greet("Hello %s, %s, %s, %s, and %s!\n",
qw(Sarathy Jan Sparky Murray Mike));
use Inline (
C => Config =>
FORCE_BUILD => 1,
CLEAN_AFTER_BUILD => 0,
);
use Inline C => <<'END_OF_C_CODE';
#include <stdarg.h>
void greet(char *fmt, ...) {
Inline_Stack_Vars;
char *p, *sval;
int i =1;
int len = Inline_Stack_Items;
for(p = fmt; *p; p++) {
if(*p != '%') {
putchar(*p);
continue;
}
switch (*++p) {
case 's':
if( i >= len) {
croak("not enough arguments\n");
}
printf("%s", SvPV(Inline_Stack_Item(i), PL_na));
i++;
break;
default:
putchar(*p);
break;
}
}
Inline_Stack_Void;
}
END_OF_C_CODE