LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-20-2009, 10:58 AM   #1
famsinyi
LQ Newbie
 
Registered: Nov 2007
Posts: 25

Rep: Reputation: 0
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?
 
Old 09-20-2009, 11:27 AM   #2
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
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

Last edited by carbonfiber; 09-20-2009 at 11:30 AM.
 
Old 09-20-2009, 01:37 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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?

Last edited by paulsm4; 09-20-2009 at 01:40 PM.
 
Old 09-20-2009, 02:04 PM   #4
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
Quote:
Originally Posted by paulsm4 View Post
"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 View Post
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.
 
Old 09-20-2009, 02:50 PM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 09-21-2009, 09:06 AM   #6
famsinyi
LQ Newbie
 
Registered: Nov 2007
Posts: 25

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
glibc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't find a function in a program's source code 2.718281828 Programming 2 12-01-2006 07:37 PM
where can I find some c++ source code to learn? brucebird Programming 2 09-16-2006 01:26 AM
source code for libc function dvm Programming 1 12-27-2004 06:04 PM
source code for read() function ? Mike Davies Linux - Software 1 11-03-2004 02:10 PM
Where can i find source code rajaryan Linux - Newbie 2 03-27-2003 06:50 PM


All times are GMT -5. The time now is 12:56 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration