2

我想访问string.h. 我的意思是包含所有可用函数定义的文件string.h

例如strcpy()是一个函数string.h;我在哪里可以得到它的定义,因为string.h只给出了函数的原型?

4

5 回答 5

4

您没有指定开发人员工具 - 此答案适用于 Windows 上的 Visual Studio 2008。CRT 源可以在以下位置找到:

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

如果它安装在默认位置。对于其他版本的 Visual Studio,只需将9.0部分替换为10.0(VS 2010) 或11.0(VS 2012)。

您不会找到单个 string.c 文件 - 几个函数在它们自己的.c文件中实现(其中一些是在汇编中实现的)。

每个工具/操作系统的源位置和可用性会有所不同。

于 2013-06-20T05:25:06.317 回答
1

Probably it's problematic to find definitions but have a look at this: http://www.cplusplus.com/reference/cstring/?kw=string.h

于 2013-06-20T06:16:26.350 回答
1

为什么不试试glibc的副本,它包含所有 c 函数的源代码,或者您可以获取PJ Plauger 的书“标准 C 库”的副本。

于 2013-06-20T05:33:10.023 回答
1

C 标准库的源代码实现将取决于您使用的环境和编译器。如果你在 Linux 上编程,你可能会使用 glibc,它是开源的,可以在这里免费下载。

顺便说一下,这是它对 strcpy 的实现:

/* Copyright (C) 1991, 1997, 2000, 2003 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <stddef.h>
#include <string.h>
#include <memcopy.h>
#include <bp-checks.h>

#undef strcpy

/* Copy SRC to DEST.  */
char *
strcpy (dest, src)
     char *dest;
     const char *src;
{
  char c;
  char *__unbounded s = (char *__unbounded) CHECK_BOUNDS_LOW (src);
  const ptrdiff_t off = CHECK_BOUNDS_LOW (dest) - s - 1;
  size_t n;

  do
    {
      c = *s++;
      s[off] = c;
    }
  while (c != '\0');

  n = s - src;
  (void) CHECK_BOUNDS_HIGH (src + n);
  (void) CHECK_BOUNDS_HIGH (dest + n);

  return dest;
}
libc_hidden_builtin_def (strcpy)
于 2013-06-20T05:26:18.833 回答
0

取决于您的操作系统和编译器。

#include<...> //Will look up default include directory
#include "..." //Will look up specified path in between the "..."

每个操作系统的默认包含目录都不同,

看看这个: http: //gcc.gnu.org/onlinedocs/cpp/Search-Path.html

于 2013-06-20T05:26:18.677 回答