Re: How does printf() works




"Sanchit" <sanchitgupta.1@xxxxxxxxx> wrote in message news:cbdde0a1-0a51-46cf-a671-dd590d918bad@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I want to know how does printf (stdio library function) works? Does
this depand on complier (I am using gcc on Linix)

Does it uses some buffer in which it stores all what needed to be
printed and in end of program it prints that or something else.

Think how you'd write a cutdown sprintf(). Let it take only %d, %c and %s format specifiers.
You'd have to set up a variable argument list, then step through the format string to determine what had been passed, then call va_arg with the right type to get the argument. Then you need to convert ints to human-readable ascii characters, and pass out to the buffer.

printf() works in roughly the same way, though with lots of bells and twiddles.


--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.



Relevant Pages

  • [PATCH] Clean up empty_zero_page abuse
    ... > zero after boot. ... This patch (against EWB's boot segment patch) fixes the abuse of ... # A buffer of size EDDMAXNR*is reserved for our use ... -# A second one-byte buffer, EDDNR, in the empty_zero_page stores ...
    (Linux-Kernel)
  • [PATCH] dont abuse empty_zero_page (x86)
    ... # A buffer of size EDDMAXNR*is reserved for our use ... -# A second one-byte buffer, EDDNR, in the empty_zero_page stores ... * is for the command line. ... -Summary of empty_zero_page layout (kernel point of view) ...
    (Linux-Kernel)
  • The Ring buffer Is Overflowed
    ... "The Ring buffer that stores the incoming mouse data is ... "This event record indicates that the buffer that stores ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: How to force fscanf to find only data on a single input line?
    ... find it) to read in a line, and then parse it with sscanf. ... that every call creates a new buffer that must be managed, ... Free games and programming goodies. ...
    (comp.lang.c)
  • Carriage Return/Line Feed Problem
    ... I wrote some code that gets the HTML from a Web page and stores it in a ... buffer, then I display the buffer in a big multiline CEdit box. ...
    (microsoft.public.vc.mfc)