Where is the implementation of strlen() in GCC?

后端 未结 10 1070
梦毁少年i
梦毁少年i 2021-02-04 01:21

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

10条回答
  •  臣服心动
    2021-02-04 01:58

    Although the original poster may not have known this or been looking for this, gcc internally inlines a number of so-called "builtin" c functions that it defines on its own, including some of the mem*() functions and (depending on the gcc version) strlen. In such cases, the library version is essentially never used, and pointing the person at the version in glibc is not strictly speaking correct. (It does this for performance reasons -- in addition to the improvement that inlining itself produces, gcc "knows" certain things about the functions when it provides them, such as, for example, that strlen is a pure function and that it can thus optimize away multiple calls, or in the case of the mem*() functions that no aliasing is taking place.)

    For more information on this, see http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

提交回复
热议问题