我想訪問string.h
的源文件。我的意思是具有string.h
中所有可用功能定義的文件。我在哪裏可以找到string.cpp的源碼
例如strcpy()
是string.h
中的功能;我在哪裏可以得到它的定義,因爲string.h
只給出了函數的原型?
我想訪問string.h
的源文件。我的意思是具有string.h
中所有可用功能定義的文件。我在哪裏可以找到string.cpp的源碼
例如strcpy()
是string.h
中的功能;我在哪裏可以得到它的定義,因爲string.h
只給出了函數的原型?
您沒有指定開發人員工具 - 此答案適用於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
文件中實現(其中一些在彙編中實現)。
每個工具/操作系統的源位置和可用性會有所不同。
取決於您的操作系統和編譯器。
#include<...> //Will look up default include directory
#include "..." //Will look up specified path in between the "..."
默認include目錄對於每個操作系統不同,
雖然是用於頭文件。我認爲OP實際上是在尋找標準庫函數的實現。 – hugomg
爲C標準庫中的代碼實現將取決於什麼樣的環境和編譯器,你正在使用。如果你在Linux上編程,你可能使用glibc,這是開源的,可以自由下載here。
下面是其實現的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)
你爲什麼不嘗試的glibc副本有源爲所有的C函數或者你可以抓住的 P.J. Plauger's book, "The Standard C Library副本。
你也可以通過這個GNU圖書館,http://www.gnu.org/software/libc/index.html – freesoul
也許這就是問題找到定義,但看看這個: http://www.cplusplus.com/reference/cstring/?kw=string.h
這是一種連接實施的一大點。不過,編譯器的實現可能是開源的。我不確定標準庫如何適應這一點。 – chris
嘗試查看'gcc'源代碼。 – devnull