printf

I

italy

Hi John,

Your best bet is to download libc and grab the source from there.
However, I'm willing to bet it's fairly complex and not so trivial.
-Adam Roan
 
I

infobahn

Johan said:
Hi,

Where can I find the source for printf ?

You can find a rudimentary implementation on p156 of
K&R2. Admittedly it calls the real printf to do much of the
work, but there's enough there to give you the essence.

Or you could get a copy of the GNU library source.

Here's the source provided by Microsoft:

int __cdecl printf (
const char *format,
...
)
/*
* stdout 'PRINT', 'F'ormatted
*/
{
va_list arglist;
int buffing;
int retval;

va_start(arglist, format);

_ASSERTE(format != NULL);

_lock_str2(1, stdout);

buffing = _stbuf(stdout);

retval = _output(stdout,format,arglist);

_ftbuf(buffing, stdout);

_unlock_str2(1, stdout);

return(retval);
}

Not much help, is it?
 
R

Richard Bos

Johan said:
Where can I find the source for printf ?

That depends on what you need it for. If you want the source for _a_
version of printf(), at least one, probably several, are available on
the web. Of course, they're likely to be pretty much implementation-
specific, so they might be useless with your compiler. If you want the
source for _your_ version of printf(), you'll have to ask your vendor.

Richard
 
D

dcorbit

Somewhat related to the FAQ:

18.13: Where can I find the sources of the standard C libraries?

A: The GNU project has a complete implementation at
http://www.gnu.org/software/libc/. Another source (though not
public domain) is _The Standard C Library_, by P.J. Plauger (see
the Bibliography). See also questions 18.9b, 18.15c, and 18.16.

Many C compilers come with the runtime source for their own
implementation of the standard C libraries.
 
B

Ben Pfaff

Johan said:
Where can I find the source for printf ?

I wrote a simple implementation that should be reasonably
portable for Pintos, my instructional operating system. It does
not support floating-point formatting, it has a few limitations
that are probably not entirely standard compliant, and its code
is not entirely comp.lang.c compliant. Given those constraints,
you are welcome to take a look at it. It is in file
pintos/src/lib/stdio.c in the tar archive available at
http://www.stanford.edu/class/cs140/pintos/pintos.tar.gz
 
B

Ben Pfaff

Ben Pfaff said:
I wrote a simple implementation that should be reasonably
portable for Pintos, my instructional operating system. It does
not support floating-point formatting, it has a few limitations
that are probably not entirely standard compliant, and its code
is not entirely comp.lang.c compliant. Given those constraints,
you are welcome to take a look at it. It is in file
pintos/src/lib/stdio.c in the tar archive available at
http://www.stanford.edu/class/cs140/pintos/pintos.tar.gz

Come to think of it, I can even provide a direct link:
http://www.stanford.edu/class/cs140/pintos/pintos/src/lib/stdio.c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,158
Messages
2,570,880
Members
47,414
Latest member
djangoframe

Latest Threads

Top