problems with stdarg.h and own printf
Posted: Wed Dec 05, 2007 10:49 am
I have the following stdarg.h:
This is my printf:
Whenever I use va_arg I get this error: "lvalue required as increment operand". I have an old kernel which uses the same macros and it does compile, but this code doesn´t. I use gcc 4.2.1 (for both).
Code: Select all
typedef uint8t *va_list;
#define va_start(ap, v) ((void) (ap = (va_list) &v + sizeof(v)))
#define va_arg(ap, type) (*((type *)(ap))++)
#define va_end(ap) ((void) (ap = 0))
Code: Select all
void printf(char *format, ...) {
va_list argptr;
char s[34], c, *str;
int num;
va_start(argptr,format);
while(*format != '\0') {
if(*format != '%') {
putchar(*format);
} else {
*format++;
switch(*format) {
case '%':
putchar('%');
break;
case 'b':
num= va_arg(argptr,int);
itoa(s,num,2,PRINTF_SMALL);
printf(s);
break;
case 'c':
c= va_arg(argptr,char);
putchar(c);
break;
case 's':
str= va_arg(argptr,char *);
printf(str);
break;
case 'x':
num= va_arg(argptr,int);
itoa(s,num,16,PRINTF_SMALL);
printf(s);
break;
case 'X':
num= va_arg(argptr,int);
itoa(s,num,16,PRINTF_BIG);
printf(s);
break;
case 'd':
num= va_arg(argptr,int);
itoa(s,num,10,PRINTF_SMALL);
printf(s);
break;
default:
putchar(--*format);
putchar(++*format);
break;
}
}
*format++;
}
va_end(argptr);
}