[SOLVED] why I couldn't find the source code of printf function in glibc source?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
why I couldn't find the source code of printf function in glibc source?
I'm trying to study how function in c++ library calls the kernel system call. I performed a 'grep' command to search the glibc-2.5 source code, but what I can find is only the function prototype of printf function as follow:
./libio/stdio.h:extern int printf (__const char *__restrict __format, ...);
I couldn't locate the function definition (implementation) of 'printf'
glibc (GNU C Library) is, as the name suggests, GNU's version of the C standard library (rather than C++). However, what arguments did you pass to grep in order to search for printf? Take a look inside stdio-common/printf.c
Last edited by carbonfiber; 09-20-2009 at 11:30 AM.
Actually, "printf" is often implemented along with the C compiler. You'll definitely find "write()" (which printf uses) in glibc, but not necessarily "printf()" itself.
Try this:
Google printf.c+source
'Hope that helps .. PSM
PS:
You brought up an interesting point when you said "function in c++ library calls the kernel". As you see in the glibc source, the standard library is written in *C* (not "C++").
"C" is to "C++" very much what "write" is to "printf".
"printf" is often implemented along with the C compiler
That would pretty odd as it is normally not the compiler's job to provide it. Could you give examples of compilers that do?
Quote:
Originally Posted by paulsm4
You'll definitely find "write()" (which printf uses) in glibc, but not necessarily "printf()" itself.
write() is not part of the standard C library. printf() is. In other words, in the absence of printf() - glibc could be considered incomplete to say the least.
Look, carbonfiber - I want to help famsinyi, not defend myself against you.
What you told him is true - thank you. What I told him is also true. If you doubt it, I suggest you try looking harder.
As far as "glibc-2.5": I confess, I don't know. As far as "C runtime libraries" in general: there's considerable diversity, depending on a) platform, b) vendor, c) version, d) many, many other factors.
famsinyi - please let us know what you find, and please post back if you have any questions.
thank you very much paulsm4, carbonfiber. I think the definition should be located in stdio-common/printf.c. The marcro
ldbl_strong_alias (__printf, printf);
should have made a link within __printf and printf. I found a document giving some explanation about strong and weak alias. It could be found on the web with this keyword "reading glibc source code". The issue should be related to how assembler determines what symbol to use for a function. I'm not very sure now and need more study. I'll get back here after I really get the understanding.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.