Eric Wilhelm wrote:
# The following was supposedly scribed by
# Eric Wilhelm
# on Saturday 21 August 2004 07:38 pm:


Is there a "vgmp_printf" function? Sounds like you'll need one.


Okay, there is gmp_vprintf(), but it isn't going to do you any good.

Looking at the minprintf() example in K&R's "The C Programming Language", it sounds like you're basically going to end up doing the same thing unless you can discover the non-portable tricks that everyone keeps talking about.

An excerpt of my adaptation:

  case 's':
    sv = va_arg(ap, SV *);
    if(! SvPOK(sv))
      croak("not a valid string\n");

I think va_list is absolutely the wrong way to go. I've been messing with it a little and can't get even the SvPOK call above to not segfault.


I've struck something similar. I was trying the following (which I thought *should* work, but which prints out a couple of wrong values, then segfaults):


use Inline C => <<'EOC';

#include <stdio.h>
#include <stdarg.h>

void wrap1(SV * a, ...) {
     Inline_Stack_Vars;
     int i;
     va_list ap;

     va_start(ap, a);

     for(i = 1; i < Inline_Stack_Items; ++i)
        printf("%#o ", SvIV(va_arg(ap, SV *)));

     va_end(ap);
     printf("\n");
}


EOC

wrap1("%#o %#o %#o %#o\n", 37, 22, 11, 10);



I'll have to think further about the other points you raise in this post (and also about the ideas presented by David).

Thanks guys.

Cheers,
Rob

Basically, my understanding is that the Inline_Stack_Vars macros take the place of the va_start and va_args, etc.

So, because you can't (portably) build a var-arg list at runtime, you're stuck refactoring or rewriting whatever C code you're trying to use (as in vprintf, etc.)

Maybe you'll have to step-through the format and use sprintf on each element, then printf the result.

Maybe you should just dynamically write some static code and use Inline::C in that way.

--Eric





Reply via email to