如何获取当前C程序中的函数列表 [英] How get list of functions in current C program

查看:101
本文介绍了如何获取当前C程序中的函数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想得到当前C

代码中定义的所有函数的列表,例如,如果我有以下代码:


int f(int c,int d){

int a = 10;

int b = 12;

返回c + a;

}


int g(无效){

...

...

}


int main(){

}

我需要一个能给我* f *和* g *的函数。


谢谢,

-

Shirvani Ali

Hi all,
I want to get list of all functions that are defined in the current C
code, for example if I have the code below:

int f(int c, int d){
int a = 10;
int b = 12;
return c+a;
}

int g(void){
...
...
}

int main(){
}
I need a function that give me *f* and *g*.

thanks,
--
Shirvani Ali

推荐答案

Ali Shirvani写道:
Ali Shirvani wrote:

大家好,

我想得到当前C

代码中定义的所有函数的列表,例如,如果我有以下代码:


int f (int c,int d){

int a = 10;

int b = 12;

返回c + a;

}


int g(无效){

...

...

}


i nt main(){

}


我需要一个能给我* f *和* g *的函数。
Hi all,
I want to get list of all functions that are defined in the current C
code, for example if I have the code below:

int f(int c, int d){
int a = 10;
int b = 12;
return c+a;
}

int g(void){
...
...
}

int main(){
}
I need a function that give me *f* and *g*.



...但不是* main *?


C语言本身无法做到这一点。也许您的系统上某些特定于平台的实用程序可能能够满足您的需求。在Unixoid系统上,您可以从

" nm"开始。实用程序,看看你能在它上面构建什么。


-
呃********* @ sun.com

... but not *main*?

The C language itself has no way to do this. Perhaps some
platform-specific utilities on your system might be able to do
what you require. On a Unixoid system, you might begin with the
"nm" utility and see what you can build atop it.

--
Er*********@sun.com


11月17日下午2:05 *,Ali Shirvani < aj ********* @ gmail.comwrote:
On Nov 17, 2:05*pm, Ali Shirvani <aj*********@gmail.comwrote:

大家好,

我想得到的列表所有在当前C

代码中定义的函数,例如,如果我有以下代码:


int f(int c,int d){

* * int a = 10;

* * int b = 12;

* *返回c + a;
< br $>
}


int g(无效){

* * ...

* *。 ..


}


int main(){


}


我需要一个能给我* f *和* g *的函数。


谢谢,
Hi all,
I want to get list of all functions that are defined in the current C
code, for example if I have the code below:

int f(int c, int d){
* *int a = 10;
* *int b = 12;
* *return c+a;

}

int g(void){
* *...
* *...

}

int main(){

}

I need a function that give me *f* and *g*.

thanks,



void get_f_and_g(int(** f_result)(int c,int d),

int(** g_result)(void))

{

* f_result = f; // f和g当然需要在范围内,当然

* g_result = g;

}


Sebastian

void get_f_and_g(int (**f_result)(int c, int d),
int (**g_result)(void))
{
*f_result = f; // f and g need to be in scope, of course
*g_result = g;
}

Sebastian


>我想得到当前C
中定义的所有函数的列表
>I want to get list of all functions that are defined in the current C

>代码,例如,如果我有以下代码:
>code, for example if I have the code below:



有许多工具可以对源代码进行操作,并且将会是

给你这样的信息。例如,cproto将给出

一个外部函数原型列表。 (以及

课程,其中包括函数名称)。这些依赖于能够将C源代码作为文本文件读取,并且相当便携。

其中一些调用C预处理器,这是不可移植的。一些没有调用C预处理器的
可能会被用于定义函数的
宏弄糊涂。


可执行文件或目标文件也可能包含函数名称

(如果没有剥离)适当地修改(某些实现添加

a引导下划线或对名称进行其他更改以避免

汇编关键字。在C ++中,函数名称可能会被严重损坏

来表示参数和返回类型。)。诸如nm之类的工具。或者

" objdump"可能有空位。通常有一个符号

" type"这允许您区分函数和变量,

以及识别静态名称和非静态名称。这一切都非常依赖于b $ b系统。


无法保证正在运行的可执行文件能够准确找到自己的

名称,如果确实如此,它可以打开可执行文件

来查看符号。当然,查看符号是非常依赖于系统的


There are a number of tools that operate on source code and will
give you information like this. "cproto", for example, will give
you a list of prototypes for the external functions. (and, of
course, those include the function names). These depend on being
able to read C source code as a text file, and are fairly portable.
Some of them invoke the C preprocessor, which isn''t portable. Some
of those that don''t invoke the C preprocessor can get confused by
macros used in defining functions.

An executable or object file may also contain the function names
(if not stripped) mangled appropriately (some implementations add
a leading underscore or make other changes to the name to avoid
assembler keywords. In C++ the function name may be horribly mangled
to indicate argument and return types.). Tools such as "nm" or
"objdump" may be available. It is common that there is a symbol
"type" that allows you to distinguish between functions and variables,
and to identify static vs. non-static names. This is all very
system-dependent.

There is no guarantee that a running executable can find its own
name accurately, and if it does, that it can open up the executable
to look at the symbols. And, of course, looking at the symbols is
very system-dependent.


> int f(int c,int d) {

int a = 10;

int b = 12;

返回c + a;
}

int g(void){

...

...
}
int main(){
}

我需要一个能给我* f *和* g *的函数。
>int f(int c, int d){
int a = 10;
int b = 12;
return c+a;
}

int g(void){
...
...
}

int main(){
}
I need a function that give me *f* and *g*.



是否有任何特殊原因导致此函数* * *

为您提供main,printf, ;退出"," getchar"等等?

Is there any particular reason why this function should *NOT* also
give you "main", "printf", "exit", "getchar", etc. ?


这篇关于如何获取当前C程序中的函数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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