views:

443

answers:

5

Can anyone point me to the definition of strlen() in GCC? I've been grepping release 4.4.2 for about a half hour now (while Googling like crazy) and I can't seem to find where strlen() is actually implemented.

+1  A: 

shouldn't you look in source code of the appropriate library instead of GCC?

EMPraptor
Different compilers keep their CRT functions in different places.
Crashworks
+8  A: 

You should be looking in glibc, not GCC -- it seems to be defined in strlen.c -- here's a link to strlen.c for glibc version 2.7... And here is a link to the glibc SVN repository online for strlen.c.

The reason you should be looking at glibc and not gcc is:

The GNU C library is used as the C library in the GNU system and most systems with the Linux kernel.

Mark Rushakoff
I even have glibc and didn't think to look. Pretty wifty. Thanks for the heads up.
Chris
Meh, that's not very optimized. At least with Visual C++ we get a decent assembly language strlen.
toto
"The GNU C library is primarily designed to be a portable and high performance C library." I'm guessing they are placing more weight on the portability part, maybe.
Mark Rushakoff
jbcreix
+3  A: 

Is this what you are looking for? strlen() source. See the git repository for more information. The glibc resources page has links to the git repositories if you want to grab them rather than looking at the web view.

faran
+1  A: 

Here's the bsd implementation

size_t
strlen(const char *str)
{
        const char *s;

        for (s = str; *s; ++s)
                ;
        return (s - str);
}
hyperlogic
+2  A: 

Google Code Search is a good starting point for questions like that. They usually point to various different sources and implementations of a function.

In your particular case: GoogleCodeSearch(strlen)

cschol