Is there something wrong with my code for the 'stdarg' macros shown here
Code:
typedef void *va_list;
#define va_rounded_size(T) \
(((sizeof(T)+sizeof(int)-1)/sizeof(int))*sizeof(int))
#define va_start(ap,lastarg) \
( ap=(va_list)((char *)&(lastarg)+va_rounded_size(lastarg)) )
#define va_arg(ap, T) \
(ap = (va_list) ((char *) (ap)+va_rounded_size(T)), \
*((T *) (void *) ((char *) (ap)-va_rounded_size(T))))
I used them in a function like this
Code:
void testf(char *msg, ...)
{
va_list ap;
int d;
va_start(ap,msg);
kprintf("\nmsg=0x%X ap=0x%x",&msg,ap);
d=va_arg(ap,int);
kprintf("\n%d @ %X",d,ap);
}
void kmain(void)
{
setbgcolor(BLACK,FALSE);
loadIDT();
testf("Hello",10,20,30,40,50,60,70,80,90);
}
But never get the correct value of the second or subsequent arguments printed, instead I get something other weird value shown below.
Code:
msg=0x104FF4 ap=0x104ff8
33095686 @ 104FFC
I first wrote this in a normal C program and tested it there and it worked fine, however it does not in my kernel.
I can't figure out what is wrong here, I hope someone here will be able to spot what I've done wrong, this has been bugging me for a while now.