var_args problems in C... any ideas?

Paul Damien Mclachlan ((no email))
Mon, 12 Dec 1994 17:05:32 +1100 (EST)

OK... here's a toughie...

OK... I'm trying to write a function that is close to scanf, but horribly more complex once you look at it. (I think so, anyway)

consider:

void interface( char *typelist, char *instring, void *function )

where typelist is a scanf type string, eg "%c%d%s"
instring is a list to scan from, eg "a14hello there"
and function is a function to call. In the above example it would be:

void function( char g, int num, char *str );

see what I mean? I need a way to generate a var_args style list, without actually using var_args, because they are just used for reading varargs, not passing them, as far as I can tell.

I'd preferably like a way to do it without having to consider each possible permutation of the typelist string, and I'd really like to be told it can be done in portable C... I could do it on a PC, with stack based passing using just a little hack - but thats not very portable - and I wouldn't have a clue how to do it so that it would work on ftoomsh anyway!

btw... the actual use of this code is very good - this is a highly simplified example, but anyway :P

I'd appreciate any help from all you clever ppl out there.... because I've spent a day on it and don't have a clue!

Regards,

Paul