简体   繁体   English

如何在eclipse中检查c标准库函数源代码

[英]how to check c standard library function source code in eclipse

I'm currently learning c and want to know how a standard library function is implemented eg 我目前正在学习c,想知道如何实现标准库函数,例如

在此处输入图片说明

I control click ed on the fgets function and it took me to the function prototype declaration of fgets in stdio.h header file. control clickfgets函数的control click ed,并带我去了stdio.h头文件中fgets的函数原型声明。

在此处输入图片说明

But I want to see how fgets is implemented, not its function prototype. 但是我想看看fgets是如何实现的,而不是它的功能原型。 Is there anyway to see its internal implementation? 无论如何,有没有看到它的内部实现?

The source code for some standard library implementations, such as glibc , are available online, and you can look up its fgets() code . 某些标准库实现(例如glibc的源代码可在线获得,您可以查找fgets()代码 But the source code isn't typically installed on a development PC unless you're building your own toolchain for some reason (eg, a cross-compiler). 但是,除非出于某种原因(例如,交叉编译器)构建自己的工具链,否则通常不会在开发PC上安装源代码。 In fact, portions of the source code are often written in assembly. 实际上,部分源代码通常是用汇编编写的。 Only the compiled object files are usually installed on development / target PCs. 通常只有编译的目标文件安装在开发/目标PC上。 Therefore, your IDE doesn't have access to the source and can't show it to you. 因此,您的IDE无权访问源,也无法向您显示源。 Other standard libraries like Microsoft's MSVCRT are proprietary and the source code is not available, only the compiled library. 其他标准库(例如Microsoft的MSVCRT)是专有的,并且源代码不可用,只有编译后的库可用。 You can always disassemble that of course, but the output is not likely to be very useful to you. 您当然可以随时对其进行反汇编,但是输出对您不太可能有用。

In general most (not all!) C/C++ programmers treat standard library functions as black boxes and rely on good reference documentation to understand their behavior. 通常,大多数(不是全部!)C / C ++程序员将标准库函数视为黑盒,并依靠良好的参考文档来了解其行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM