Where is the implementation of strlen() in GCC?

后端 未结 10 1074
梦毁少年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:53

    I realize this question is 4yrs old, but gcc will often include its own copy of strlen if you do not #include and none of the answers (including the accepted answer) account for that. If you forget, you will get a warning:

    file_name:line_number: warning: incompatible implicit declaration of built-in function 'strlen'

    and gcc will inline its copy which on x86 is the repnz scasb asm variant unless you pass -Werror or -fno-builtin. The files related to this are in gcc/config//.{c,md}

    It is also controlled by gcc/builtins.c. In case you wondered if and how a strlen() was optimized to a constant, see the function defined as tree c_strlen(tree src, int only_value) in this file. It also controls how strlen (amongst others) is expanded and folded (based on the previously mentioned config/platform)

提交回复
热议问题