number of arguments function for 4.1bsd VAX cc(1) -- TYPO FIX

Eugene D. Brooks III brooks at lll-crg.ARPA
Tue Feb 26 04:09:58 AEST 1985


> int
> numargs()
> {
>     asm("        clrl    r1");
>     asm("        subb3   8(fp),$92,r1");
>     asm("        ashl    $-2,r1,r0");		/* changed $2 to $-2 */
> }

I can't fathom how this one works.  Here is the one I use for all Vax PCC ports.
As the stack frame for the Vax is hardwired by the call instruction it should
work on all vax C compilers that use CALLS for their routine linkage.

int getnargs()
{
	asm("	movl 8(fp),r0");	/* Move the AP of the caller into r0. */
	asm("	movzbl (r0),r0");	/* The arg count is a byte at (AP). */
#ifdef lint
	return(0);			/* Lets keep lint useful. */
#endif
}

BUGS/FEATURES
The value returned is the number of argument words.  If there is a
double in the argument list it increments the argument count by 2.
The same bug/feature exists for structure arguments.  For my use of
the routine this was a desired feature.



More information about the Comp.lang.c mailing list