Implementing C varargs in assembler
Posted: Sat Apr 24, 2004 1:33 am
Hi,
I'm writing a kprintf function for my kernel in assembly language, and I've been studying the sources of RedHat's newlib for clues. But I can't really see how variable argument lists are implemented behind the scenes.
How does a C function know how many arguments were passed to it? (Is there something on the stack frame that can act like a sentinel so it can count the arguments? Just looking at the number of %-format conversions isn't a very robust way of counting arguments passed!) What do the va_start and va_end macros expand to?
Thanks for your help.
I'm writing a kprintf function for my kernel in assembly language, and I've been studying the sources of RedHat's newlib for clues. But I can't really see how variable argument lists are implemented behind the scenes.
How does a C function know how many arguments were passed to it? (Is there something on the stack frame that can act like a sentinel so it can count the arguments? Just looking at the number of %-format conversions isn't a very robust way of counting arguments passed!) What do the va_start and va_end macros expand to?
Thanks for your help.