从c中导入的标头中使用了哪些函数? [英] What functions are used from an imported header in c?

查看:70
本文介绍了从c中导入的标头中使用了哪些函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读用C编写的庞大代码库.在某些文件中,包含一些标头,但未指定需要的标头.我想知道是否可以通过某种方式查看当前文件中特定标头使用的功能,而不必通读两个文件中的全部代码.

I am reading through this huge code base which is written in C. In some of the files there are some headers which are included, the need for which is not specified. I wanted to know if there is any way that I can look at what functions are used from a particular header in the current file without having to read through the whole code in both files.

推荐答案

有一些选择:

查看是否需要某些内容的一种快速方法是注释掉头文件,并查看编译时遇到的问题.但是,这样做有一些陷阱,因为您可能仍会将该头文件包含在其他文件中.

One quick way to see whether something is needed is to comment out a header file and see what breaks on compilation. There are some pitfalls with this, though, because you might still be including that header in some other file.

您可以在GCC中使用-M标志来获取依赖项列表,如下所示:

You can use the -M flag with GCC to get a list of dependencies, like this:

    gcc -M file.c

或者,如果要排除所有包含的系统,则可以使用:

Or, if you want to exclude all the system includes you can use:

    gcc -MM file.c

这将为您提供哪些标头包括哪些其他标头的列表.这不会直接告诉您哪个函数来自何处,但可以帮助您找出给定标头可能在代码中起作用的所有位置.

This will give you a list of what headers include what other headers. This doesn't directly tell you which functions came from where, but it will help you figure out all the places a given header might be working its way into the code.

使用停止编译文件

   gcc -E file.c > file.txt

这将为您提供预处理器发送到编译器的输出.您需要重定向输出,因为此选项会将其输出放置在stdout上.

This will give you the output that the preprocessor sends to the compiler. You'll need to redirect the output, as this option places its output on stdout.

大多数标准标题都有手册页.您可以这样做,例如

Most standard headers have man pages. You can do, for example

    man stdio

查看有关stdio.h中包含内容的页面.如果您从未看过这些内容,则它们通常令人惊讶地具有教育意义.

to see a page for what is included in stdio.h If you've never looked through these, they are often surpisingly educational.

这篇关于从c中导入的标头中使用了哪些函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆