Writing own printf function without using stdarg.h

Discussion in 'C' started by osfreak, Sep 5, 2010.

  1. osfreak

    osfreak New Member

    Sep 5, 2010
    Likes Received:
    Trophy Points:

    I am trying to write my own printf function . I dont want to use the stdarg.h since i am going to use this function in real mode (during booting). So i need to access the arguments from memory directly.

    I want to understand how the arguments are stored when they are passed to the stack. I am using the gcc compiler on linux to compile and run my programs ..

    I already have routines to print short, long, int and characters. This is how i plan to implement my function :

    int printf(char *str,...)

    Sample call : printf ("%c%d",'a',45)

    In printf , I will have the address of the string str so I will scan that and count the number of arguments and their types. Now using this information and the address of the first argument str, I need to get access to the other arguments on the stack .

    I dont want to add checks and just want basic functionality.

    Any help is appreciated.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice