another c bug?
chris at MIMSY.UMD.EDU.UUCP
chris at MIMSY.UMD.EDU.UUCP
Sat Aug 2 09:32:01 AEST 1986
This is not a compiler bug. It is not legal to take the address
of one argument and use that to compute the address of another
argument. It works on all pure stack machines as long as you know
the direction of stack growth. It does not work on mixed stack/register
machines like the Pyramid.
The proper thing to do in larn's case is to use varargs and vprintf.
I am not sure if vprintf is in the `ucb universe' C library, but
vprintf(fmt, args)
char *fmt;
va_list args;
{
_doprnt(fmt, args, stdout);
}
should work (since I know how Pyramid did their varargs). Given
vprintf, change
show_int_args (args)
int args;
{
int *pargs;
int i;
pargs = &args;
while (*pargs != 0)
printf ("%d : ", *pargs++);
printf ("%d\n", 0);
}
to
#include <varargs.h>
show_int_args(va_alist)
va_dcl
{
register int i;
va_list p;
va_start(p);
for (;;) {
i = va_arg(p, int);
if (i == 0)
break;
printf("%d : ", i);
}
printf("0\n"); /* simplified */
va_end(p);
}
/* emulate a standard printf() */
xprintf(va_alist)
va_dcl
{
char *fmt;
va_list p;
va_start(p);
fmt = va_arg(p, char *);
vprintf(fmt, p);
va_end(p);
}
Chris
More information about the Mod.computers.pyramid
mailing list