gripe: variable arg lists
hamilton at uiucuxc.UUCP
hamilton at uiucuxc.UUCP
Wed Dec 12 09:12:00 AEST 1984
>> ... The secret is a little subroutine that knows where arguments are to be
>> found and ... builds a contiguous memory array of them. ... I think
>> that with sufficient "cleverness", one can always get away with this
>> type of trick.
>
>Does the magic routine parse the printf string to find out how many
>arguments there are? If not, how does it determine this?
i think the "secret" subroutine he's referring to is _vaarg(), which gets
called by the va_arg macro in <varargs.h>. however, it doesn't really
build up a list; since it's called in a sequential-access mode, it only
scans a pointer across the places where args are stashed. it's main
job is figuring when that pointer needs to jump from the register frame
to the stack.
other lovers of _doprnt() who have migrated to a pyramid 90x, try this:
#include <stdio.h>
main ()
{
foo ("%d %.0f %s\n", 1, 2., "3");
}
foo (fmt, args)
char *fmt;
int args;
{
int varargs_block[3];
_doprnt (fmt, _vastart (varargs_block, &args), stdout);
}
wayne ({decvax,ucbvax}!pur-ee!uiucdcs!uiucuxc!)hamilton
More information about the Comp.lang.c
mailing list