473,668 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

printf

Hi,

Where can I find the source for printf ?

John
Nov 14 '05 #1
8 5020
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
"Johan" <me@knoware.n l> 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
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(arglis t, 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
"Johan" <me@knoware.n l> 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
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
"Johan" <me@knoware.n l> 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
Sorry for my oxmoron. Sigh. :P

Nov 14 '05 #8
Ben Pfaff <bl*@cs.stanfor d.edu> writes:
"Johan" <me@knoware.n l> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
5934
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <= 4 */ };
8
2704
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
7
96294
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %% should be used. Wouldn't it have been better (from design perspective) if the same escape character had been used in this case too. Forgive me for posting without verfying things with any standard compiler, i don't have the means for now.
188
17317
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
29
17562
by: whatluo | last post by:
Hi, c.l.cs I noticed that someone like add (void) before the printf call, like: (void) printf("Timeout\n"); while the others does't. So can someone tell me whether there any gains in adding (void) to printf. Thanks, Whatluo.
4
2004
by: pai | last post by:
Hi , Can any one tell me how this statement of printf is behaving . how the last digit is printed int a=2,b=4,c=7; printf("%d",printf("%d %d:",a,b)); //answer to this was 2 4:3
11
3908
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try to do some example to explain, However, after some trying, I confused when I try to do some integer constant division, I know I should do float division something like 3.0/6.0, but I'm still confused where the -0.124709 comes for the following...
19
9881
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement, the printf library will not be linked, so it further reduces the executable size. Is there an easy way to disable printf in a large project? In my project, we have thousands of C & C++ files. They don't have a common included common header. ...
34
15914
by: Old Wolf | last post by:
Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?
1
8501
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8797
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8583
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.