Va_*
Posted: Mon Oct 02, 2006 2:31 am
I'm having a bit of difficulty with va_ commands in my k_printf
My va functions are defined as follows (borrowed from another Barebones)
And I'm using them like this
All the put* functions are working fine as I've unit tested each of those, but when I try to parse any va statements all I get printed is a solid right facing arrow head.
Any ideas?
My va functions are defined as follows (borrowed from another Barebones)
Code: Select all
#define __va_rounded_size( TYPE ) ( ( (sizeof(TYPE) + sizeof(int) - 1) / sizeof(int) ) * sizeof(int) )
#define va_start( AP, LASTARG ) ( AP = ((char *) &(LASTARG) + __va_rounded_size(LASTARG)) )
#define va_arg( AP, TYPE ) ( AP += __va_rounded_size(TYPE), *((TYPE *) (AP - __va_rounded_size(TYPE))) )
Code: Select all
void SCR_Printf(const char *fmt, ...)
{
va_list pt;
int args = 0;
char cur, pos = 0;
while((cur = fmt[pos++]))
if(cur == '%')
args++;
if(args)
va_start(pt, args);
while((cur = *fmt++))
if(cur == '%')
{
cur = *fmt++;
switch(cur)
{
case 'd':
case 'i':
putint((int)va_arg(pt, int));
break;
case 'c':
putchar((char)va_arg(pt, char));
break;
case 's':
puts(va_arg(pt, char *));
break;
}
}
else
putchar(cur);
}
Any ideas?