va_list etc...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Jeroen Jacobs

va_list etc...

Post by Jeroen Jacobs »

Hi,

I'm thinking about writing my own OS (to learn more about OS-architecture), and well... I'm stuck... and I'm not even started yet.

I wrote a simple "Hello World !" bootsector (I think everybody tries that sooner or later), and I was thinking : Now I need a printf()-like function so I can display more useful information. I know how to use va_list and va_start in normal C-apps, but in an OS, you have to define those macros yourself.... and that's my problem.

I looked at the stdarg.h file from other Operating Systems (linux 0.1 and Thix 0.3.x), but those macro definitions don't make sense to me... I don't want to "cut & paste" them, because I want to understand the code (instead of just using it).

Do you have any information about what those macros actually do ?? It looks like voodoo to me...

Thnx in advance,

Jeroen Jacobs
Chris Giese

Re: va_list etc...

Post by Chris Giese »

Here's my stdarg.h:
http://www.execpc.com/~geezer/osd/code/inc/stdarg.h

It's a lot of C voodoo using pointers and casts and sizeof and the comma operator, but it works. It might even work with a 16-bit compiler, but I haven't checked this.

va_start() points to the first variable argument.
va_arg() advances the pointer, then evaluates to the previous argument (comma operator).
va_end() doesn't do anything.

Here's my printf(), too;
http://www.execpc.com/~geezer/osd/code/inc/_printf.h
http://www.execpc.com/~geezer/osd/code/ ... doprintf.c
Post Reply