Alex Rivera | Logout

source code of c/c++ functions

Asked 2009-07-14T18:59:09.110
36

I wanted to have a look at the implementation of different C/C++ functions (like strcpy, stcmp, strstr). This will help me in knowing good coding practices in c/c++. Could you let me know where can I find it?

Thanks.

c++ c
Edit
Report

4 Answers

18

It's worth pointing out that the source code for the C standard library does not necessarily highlight good coding practices. As the standard library, it has a special status where, for example, it can rely on a lot of unspecified or non-portable behavior simply because they know the exact compiler with which it is used.

And of course, this only tells you about C coding practices.

That has nothing to do with C++ coding practices, which are very different. Don't treat them as one language. There is no such thing as C/C++. C is a language with its own coding practices and common idioms, and C++ is a separate, independent language which also has its own practices and idioms.

Good C code is rarely good C++ code. strcpy and other C library functions are certainly not good C++ code.

answered 2009-07-14T19:17:23.053
2

"The Standarc C Library" is a specification. You want the sources for an implementation of the specification. Your C compiler may or not provide such sources - one that does is GCC.

answered 2009-07-14T19:08:00.560
0

If you use Visual Studio Professional or Team, you should be able to find the source here:

C:\Program Files\Microsoft Visual Studio 9.0\VC\crt\src

answered 2009-07-14T19:12:10.253
0

For your purposes, this book may be helpful: Mastering Algorithms with C

answered 2009-07-14T19:14:51.310

Your Answer