Friends, I have a question:

Many times in books and tutorials I'm sent to consult the Standard C Library reference. Sometimes, references are made to some Standard C function.

Where do I see the Standard C Library in a compiler. I don't see any source code in my compiler that shows me for example how printf() or scanf() works. All that I see is header files.
Could anyone show me some light in the matter?. I would like to know how I can learn about the abilities of the functions I'm using, and not just follow like a sheep, what the book tells me to code. :confused:
Thank you!.

You'll need to be consulting documentation for those. Most of the time, all of those functions will already be compiled into libraries, and your linker will reference the libraries when it puts your program together.

Many times in books and tutorials I'm sent to consult the Standard C Library reference. Sometimes, references are made to some Standard C function.

Perhaps no better place to look is the standard itself -- or at least a publicly available draft thereof.

Comments
link posted very helpful
Ah..exactly what I was looking for - ~s.o.s~
Keep 'em rolling along - Salem

Friends, I have a question:
I would like to know how I can learn about the abilities of the functions I'm using, and not just follow like a sheep, what the book tells me to code.

how about trying the msdn website? you might not get the source code, but you can find about every function what are it's possible parameters, what values it returns, and many times it even shows examples.

www.msdn.co.il

Thank you for your desire to help me.

@ Dave Sinkula: the link you provided is going to keep me bussy for a while.

The problem with reading the standard itself is that the standard is written mostly for designers/writers of compilers. New programmer students will probably find it not-too-useful. I would rather read one of the many books you can buy or free e-books, which are written for people actually writing the programs.

You are correct Ancient Dragon. I haven't learned enough to understand
most of what is in there. I'm learning now about functions and what they are, and I'm understanding them. So, I started asking myself about other functions already made, like strlen(), strcpy(), and so forth. But I don't see anywhere the actual code to know how these functions are structured. Same with printf() and scanf().
I guess I'm going to have to take it on faith and use them, even when I'm disappointed to learn that for example scanf() is not very good, for what I was using it for. Makes me wonder what else I learn in books that is not good. Thank goodness I never used gets(). :rolleyes:

I appreciate any help you guys are giving me. Thank you very much.

The actual code that implements the functions in stadnard libary are compiler-dependent -- the standards do not dictate how the functions are implemented, only what the functions should do. So one compiler might implement the functions differently then another compiler. You can get the source code for all compiler functions from GNU, which is open-source and free. But be prepared for some really nasty ( :) ) reading!

Some of the functions, like strlen() are pretty simple. Others, like printf() family of functions, get pretty complicated and difficult for newbes to follow. So I'm not sure how useful the source code would be to you at your level of understanding. Many, if not most, of the functions in the C standard library were written over 20 years ago and tested in thousands, if not millions, of programs. So you can be well assured that they work correctly as designed and documented. This doesn't mean they are good functions to use, just that they work ok.

how about trying the msdn website? you might not get the source code, but you can find about every function what are it's possible parameters, what values it returns, and many times it even shows examples.

www.msdn.co.il

I find the MSDN very difficult to navigate for the appropriate tool. You can be really thrown off into implementation-specific stuff without knowing it. They are getting to be much better, though.

The problem with reading the standard itself is that the standard is written mostly for designers/writers of compilers. New programmer students will probably find it not-too-useful. I would rather read one of the many books you can buy or free e-books, which are written for people actually writing the programs.

The library section isn't as bad as the rest.

While the standard doesn't have good example for each and every function, it is quite good at telling you exactly what ALL compilers have to do.

Whereas online references and even man pages sometimes tell you implementation-specific stuff too (whether or not you know it is left to the reader).

Or worse:
http://cppreference.com/stdio/printf.htmlCan you spot the undefined behavior that is described there, if you implemented what was stated? Do you think a newb has a chance in hell of noticing?

---

So my advice:

  • Try to do something you want to do in code.
  • Look up functions in the standard that you think are appropriate.
  • Post question(s) to forum(s) such as this when things go awry -- after reading said site's FAQ.

>>Can you spot the undefined behavior that is described there
I give up -- what is it??

scanf info in the printf description:

The %e, %f, and %g type specifiers can have the letter l before them to indicate that a double follows.

[In C90 implementations, not true C99 implementations.]

[edit]http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.9.6.1:

* An optional h specifying that a following d , i , o , u , x , or X conversion specifier applies to a short int or unsigned short int argument (the argument will have been promoted according to the integral promotions, and its value shall be converted to short int or unsigned short int before printing); an optional h specifying that a following n conversion specifier applies to a pointer to a short int argument; an optional l (ell) specifying that a following d , i , o , u , x , or X conversion specifier applies to a long int or unsigned long int argument; an optional l specifying that a following n conversion specifier applies to a pointer to a long int argument; or an optional L specifying that a following e , E , f , g , or G conversion specifier applies to a long double argument. If an h , l , or L appears with any other conversion specifier, the behavior is undefined.

This article has been dead for over six months. Start a new discussion instead.