![]() |
|
#1
|
|||
|
|||
Definitions for Standard Library Functions?I am working on a program that uses some Standard Library functions, e.g. atoi, atof, strcpy, fgets, and would like to see the source code for these functions to better understand how they do what they do.
I thought the Standard Library header files might contain function definitions but all I find is declarations and directives (no definitions For example, I searched all of Dev-C++'s header files for "fgets" and here's what I found: CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
So I'm wondering where I can find the source code for the DEFINITIONS of Standard Library functions? Maybe the definitions vary compiler to compiler, but I would think at a minimum, the GNU versions would be available. (I looked on gcc.gun.org but couldn't find library function definitions.) Thanks VERY much and if it applies to you, Merry Christmas! P.S. I have both Dev++ and MS VS VC++ compilers. Thanks again. |
|||
|
#2
|
|||
|
|||
|
Quote:
You can go to ftp://ftp.gnu.org/gnu/glibc/ and download source for glibc. Be prepared to do some digging to see the implementations of the functions. For example, starting with glibc-2.3, they deleted the fgets.c from the stdio directory and use iofgets.c from libio. As your program is compiled, somehow or other calls to fgets go through some conversions and end up calling iofgets. (So, if you want to see fgets.c, download glibc-2.2.5.tar.gz) This is just a little taste of the effort that you may expend to get to the bottom of things. Now, looking at source code of the gnu glibc library is not necessarily the best way for beginning and intermediate programmers to see what the functions actually do, but for some people it is very enlightening. You can look at the attachment (I zipped fgets.c from glibc-2.2.5/stdio) to see if you think it's worthwhile to download the entire 16 MByte source. (fgets.c is about 100 lines of source text and I didn't want to clutter the board; that's why I attached it instead of pasting it into this response.) Regards, Dave |
|
#3
|
|||
|
|||
|
Dave,
Thanks for the Christmas present! (I think... LOL) What a maze of files, but I've got some versions uzipped and am plowing my way through. My intention is to write versions of some of these functions that will meet my specific purposes. E.g. write a MyStrCpy function or a MyAToF function. Only I'll be using the code, so I have some flexibility w/ how I approach problems. Actually, after looking at all these files, it kind of makes me want to learn Assemply Language to get down to the basics of the basics. But it's not like have unlimited time. But I imagine it would be very helpful to know. Take care and THANKS AGAIN! |
|
#4
|
|||
|
|||
|
Quote:
If Santa left you a few bucks, you might try to find a reference book with some narrative surrounding the code. One such book is The Standard C Library by P.J.Plauger. This was published in 1991 or 1992 and is still in print. New from Amazon, it's a little over 50USD. Used ones can be found for under 30USD. For real down-where-the-rubber-meets-the-road C programming in general, I personally don't think you can do better than good old K&R (The C Programming Language by Brian Kernighan and Dennis Ritchie --- be sure to get the second edition). Some people say that K&R is not the best book for C beginners (it's what I learned C from), but regardless of that, I think it's a great text and reference for people slightly above the beginner status. Some really tight and totally correct C code examples. (There are a couple of web sites with errata, and at least one with answers to the exercises in this boot.) There is an online version of this at http://freebooks.by.ru/view/CProgram...age/kandr.html. Take a look! Now, IO functions are probably the hardest to follow, but aren't too difficult once you get a feel for the structs being used. Other functions, such as strcpy() are quite straightforward. If your New Year's resolution includes better understanding of C programming principles and applications, I can't think of a better way than digging into the Standard C Library (regardless of what books or reference material you choose --- and can afford). Regards, Dave |
|
#5
|
|||
|
|||
|
Thanks Dave, will check them out. But don't misunderestimate (to quote our President) the challenge of K&R.
|
|
#6
|
|||
|
|||
|
Quote:
Dave, are you familiar w/ Plauger's book on the C++ Standard Library?: http://www.amazon.com/exec/obidos/tg/detail/-/0131170031/qid=1104309331/sr=8-6/ref=sr_8_xs_ap_i6_xgl14/103-3349876-2631821?v=glance&s=books&n=507846 It goes for about $2 used on Amazon vs $38 for his book on the C Standard Library. I'm programming more in C++ than in C, but I realize that C++'s Standard Library borrows heavily from C's Standard Library, so a book on either would be helpful. Some comments mention it doesn't discuss the addition of templates to the C++ library. But for a beginner/advanced beginner programmer, do you think omission is reason not to buy the book? Thanks again for all your generous help. |
|
#7
|
|||
|
|||
|
Quote:
It was published in 1994 or 1995; I don't have a copy. Since it doesn't cover the standard template library, I didn't feel the need to buy it (but for $2.50 used, how can you go wrong!) Plauger's books are always useful and have genuine, useful, educational, working examples. The book, by Plauger and others, C++ Standard Template Library covers, guess what, the Standard Template Library (<stack>, <queue>, <map>, <list>, etc.) Since your original post indicated an interest in C standard library functions, I recommended the ones that I indicated (All standard C library functions are part of the C++ standard library.) Regards, Dave |
|
#8
|
|||
|
|||
|
Dave, I found another very helpful book on C++ that was only $3 + shipping.
"The Annotated C++ Reference Manual" by Ellis and Stroustrup. People say it's out of date, but for an understanding the basic language, I'm liking it so far. BTW, the Plauger book should be arriving any day now. |
|
#9
|
|||
|
|||
|
Quote:
The only Stroustrup reference manual that I have is the original C++ Programming Language. An excellent exposition of language features, but no namespace stuff, no standard library stuff, no STL stuff, and no other stuff that you probably want to know about. My understanding is that the Annoted C++ Reference Manual adds narrative commentary that might help understanding of the basic material, but still doesn't have the extras. (Published around 1990, I think, so certainly dated, but not necessarily bad. Just not the first or second choice for learning "modern" Standard C++ practices.) Regards, Dave |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please help with functions... | brookeville | C++ Forum | 36 | 05-Nov-2004 00:23 |
| variables in functions help | dopee | MySQL / PHP Forum | 5 | 16-Oct-2004 20:20 |
| conflict between printf and stdarg.h va functions | mirizar | C Programming Language | 3 | 12-Jul-2004 08:11 |
| Understanding functions | tommy69 | C Programming Language | 15 | 15-Mar-2004 17:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The