Jump to content
  • Advertisement
Sign in to follow this  
Padala Srikant

Where to find source code of inbuild library of c,c++

This topic is 3260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can anyone help me in getting thesource code of the standard library of c and c++ so that i can know how the are coded so that it helps me in becoming a better programmer

Share this post


Link to post
Share on other sites
Advertisement
They are typically made available by the vendor of your compiler. In particular the bulk of the C++ standard library is header-only, due to the large number of templates, so you can simply open up those header files.

I have serious doubts you will learn anything of much value this way though. Reading source code without context is often a bad way to learn. The implementation choices made by the developers of those standard libraries were made with very different reasons than your own -- reasons you may not be fully capable of understanding, even, as a beginner.

I recommend you look elsewhere for guidance. What kinds of things are you expecting to learn here? Language syntax? Design of systems? What?

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
They are typically made available by the vendor of your compiler.

I am curious whether Microsoft did publish their codes?

Anyways, if after reading jpetries advice you still want, have a look at:
* GNU libc
* GNU libc++
* eglibc (the variant to which Debian switches)

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
I am curious whether Microsoft did publish their codes?


The source code to the MSVC standard library are shipped with Visual Studio. I don't think they are with the express editions, but MSVS standard and above do come with the CRT source.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Reading source code without context is often a bad way to learn.


Not to derail the thread, but after reading that article I'm curious how beginners are supposed to go about learning. If we shouldn't look at source code and we shouldn't read tutorials what other mediums are there? Aside from school, obviously, which is hardly a fantastic place to learn about 3rd party libraries like OpenGL (at least in the case of my school). I mean, my school has some inexplicable obsession with teaching everything in java and only offers something like two entry level c/c++ classes. Should we buy books and try to learn from them, or are those crap too?

It seems that the importance of learning how to read source code is something that has been stressed to me more than once. I suppose that I'm kind of confused. The author of that article has such bad things to say about some of the biggest self-teaching methods, but doesn't point out a single alternative.

Share this post


Link to post
Share on other sites
Quote:

Not to derail the thread, but after reading that article I'm curious how beginners are supposed to go about learning

It's a valid topic.

Quote:

If we shouldn't look at source code

You shouldn't look at source code in isolation. As I explain early in the article:

Source code is devoid of context. It’s simply a miscellaneous block of instructions, often riddled with a fair bit of implicit assumptions about preconditions, postconditions, and where that code will fit in to the grand scheme of the original author’s project. Lacking that information, one can’t be sure that the code even does what the author wanted it to do! An experienced developer may be able to apply his insight and knowledge to the code and divine some utility from it (“code scavenging” is waxing in popularity and legitimacy, after all), but a beginner can’t do that.

"Code scavenging" in particular is a woefully increasingly common attempt at "solving problems" which typically does nothing to actually (a) solve a problem, (b) teach anybody anything. See examples given here.
Quote:

and we shouldn't read tutorials

You shouldn't read bad tutorials, just like you shouldn't read bad books or listen to people who don't know what they're doing. I have never said that "tutorials are bad," (or if I have, it was in a context where I was assuming the audience would understand the caveats that were to be placed on that generalization). I have observed many times that many tutorials are poorly written, a sentiment some fellow developers share. And I have specifically (in the blog post linked from the one you just read) argued that beginners should not be authoring tutorials. But tutorials can be a valid educational tool.

Source code can too, occasionally. "Don't Read Source Code" is a blog post that takes a very hard line; perhaps a more pragmatic thing to say would be that source code is probably among the least efficient educational resources since (unlike books, unlike tutorials) it is very rarely written to be educational, rather it is written to get something done (and thus lacks all that useful context I talk about, all that meat).

Quote:

Aside from school, obviously, which is hardly a fantastic place to learn about 3rd party libraries like OpenGL

OpenGL is just an API, learning how to learn an API is something a developer typically picks up over time. It just involves knowing the language in question, reading documentation, knowing how to search the web, et cetera. Learning the fundamentals of computer graphics is something many schools with decent CS degrees can teach you very well, however (although such classes are typically electives, not core classes).

Quote:

I mean, my school has some inexplicable obsession with teaching everything in java and only offers something like two entry level c/c++ classes.

Programming languages are tools; it is largely irrelevant which tools are taught to you, you will ultimately be able to understand how to apply many. Carpenters do not go to Hammer School. They do not go to Saw School or Axe School. They learn to build things, and learn that at a saw and an axe can both cut things up, but in very different ways... since they learned something higher level ('how to build things') they can extrapolate their knowledge of hammer, saw and axe more usefully than they could if they only new how to operate on (or a handful) of those tools in the small, in isolation.

The languages a school directly teaches in classes isn't usually a good metric for the quality of that school's education program.

Quote:

It seems that the importance of learning how to read source code is something that has been stressed to me more than once.

Learning how to read source code is very important, but this is a fundamentally different thing than reading source code to learn (in general).

Quote:

The author of that article has such bad things to say about some of the biggest self-teaching methods, but doesn't point out a single alternative.

I refer you to my above clarification regarding tutorials and the admission that the stance taken in that original blog post is perhaps too firm; I'm not trying to say that you should never read code, ever, I am saying that code generally the least-efficient method:

Pure source code offers no advantages and so many pitfalls that it is simply never a good choice.

...with the implication that any other methodology for self-learning you can think of is likely to be more efficient.

Share this post


Link to post
Share on other sites
Reading source code only helps if you have some semblance of what the original author was trying to do. Which is why just reading source code is a bad approach to learning how to program.

Now, if you wanted to learn how the stl vector works I would approach it like this:

- First attempt to write your own vector class. Design and implement it yourself and try your best to get it working.
- Once you have a working version or have failed to create a usable version, start looking at the stl version to see how they solved a particular problem.

Now that you've attempted a version yourself and seen how certain problems are solved in a standard version, you'll have a pretty good grasp on how a vector works without needing to know every last detail.

But, this approach will really only get you so far. IMO the best way to learn is to practice. Build a bunch of programs to do silly tasks for you. One of my first programs would calculate sales tax on a purchase for me. It was really trivial, but you'll take something away from everything you do.

Share this post


Link to post
Share on other sites
Learning to read code != learning from code.

Books are indeed a good source of information, although not all books are created equal so you are advised to ask for recommendations. For example learning about OpenGL is pretty much a case of 'pick up red book, read', learning about general 3d graphics is a case of 'pick up real time rendering, read'.

As are articles, which are not the same as tutorials, which explain concepts and maybe have some supporting code to illistrate the point. Again, not all things are created equal; most tutorials suck because they are code dumb + comments style of doing things.

The most important resource however is your own brain; having read books or decent articles the key thing is to try them out and given building blocks of knowledge consider, using your own logical thought, how you might go about doing other things. (imo this is a step many beginners miss, they expect too much hand fed to them instead of considering their own path).

At the risk of sounding like an old person; how do you think those of us who learnt to program at a young age pre-internet got on?
That's right; we got books, we read stuff and we tried things.

Share this post


Link to post
Share on other sites
I am asking that if I am asked to code a printf function which i think is not easy, than how can i achieve it without using any other inbuilt functions.......
I have no idea of how to do it.
Are there any books which can help me in this kind of stuff..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!