By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,217 Members | 1,813 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,217 IT Pros & Developers. It's quick & easy.

printf

P: n/a
Hi,

Where can I find the source for printf ?

John
Nov 14 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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

Nov 14 '05 #2

P: n/a
"Johan" <me@knoware.nl> writes:
Where can I find the source for printf ?


Whose version of printf()?
--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
Nov 14 '05 #3

P: n/a
Johan wrote:
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?
Nov 14 '05 #4

P: n/a
"Johan" <me@knoware.nl> wrote:
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
Nov 14 '05 #5

P: n/a
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.

Nov 14 '05 #6

P: n/a
"Johan" <me@knoware.nl> writes:
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.tar.gz
--
"If I've told you once, I've told you LLONG_MAX times not to
exaggerate."
--Jack Klein
Nov 14 '05 #7

P: n/a
Sorry for my oxmoron. Sigh. :P

Nov 14 '05 #8

P: n/a
Ben Pfaff <bl*@cs.stanford.edu> writes:
"Johan" <me@knoware.nl> writes:
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.tar.gz


Come to think of it, I can even provide a direct link:
http://www.stanford.edu/class/cs140/...rc/lib/stdio.c
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
Nov 14 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.