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' can someone help? |
Hello.
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 |
Hi -
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". Make sense? |
Quote:
Quote:
|
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. Thanx in advance .. PSM |
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. |
All times are GMT -5. The time now is 06:37 AM. |