473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How get list of functions in current C program

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
Nov 17 '08 #1
10 6461
Ali Shirvani wrote:
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*.
... 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

Nov 17 '08 #2
On Nov 17, 2:05*pm, Ali Shirvani <aj*********@gmail.comwrote:
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 and g need to be in scope, of course
*g_result = g;
}

Sebastian

Nov 17 '08 #3
>I want to get list of all functions that are defined in the current C
>code, for example if I have the code below:
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;
return c+a;
}

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

int main(){
}
I need a function that give me *f* and *g*.
Is there any particular reason why this function should *NOT* also
give you "main", "printf", "exit", "getchar", etc. ?

Nov 17 '08 #4
On Nov 17, 10:30*pm, gordonb.pq...@burditt.org (Gordon Burditt) wrote:
I want to get list of all functions that are defined in the current C
code, for example if I have the code below:

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;
* return c+a;
}
int g(void){
* ...
* ...
}
int main(){
}
I need a function that give me *f* and *g*.

Is there any particular reason why this function should *NOT* also
give you "main", "printf", "exit", "getchar", etc. ?
Thanks for your reply.
I'm on Linux, and I want to get only the functions that I wrote them,
there is no problem, if any thing give me list of all function, I can
ignore some of them. Is there any library that work like *nm*?

Thanks
Nov 17 '08 #5
Ali Shirvani <aj*********@gmail.comwrites:
[...]
Thanks for your reply.
I'm on Linux, and I want to get only the functions that I wrote them,
there is no problem, if any thing give me list of all function, I can
ignore some of them. Is there any library that work like *nm*?
Maybe, but that's a Linux or Unix question, not a C question. Try
comp.unix.programmer or one of the Linux newsgroups.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 17 '08 #6
Ali Shirvani wrote:
>
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*.
Simple. You parse the source code, and whenever you find a
definition for a function you extract and spit out that function
name. You might find it simpler to just read the source.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 17 '08 #7
>I need a function that give me *f* and *g*.
>>
Is there any particular reason why this function should *NOT* also
give you "main", "printf", "exit", "getchar", etc. ?

Thanks for your reply.
I'm on Linux, and I want to get only the functions that I wrote them,
So you didn't write main()?
>there is no problem, if any thing give me list of all function, I can
ignore some of them. Is there any library that work like *nm*?
You have the source code to nm, so go ahead and modify a copy of
it so instead of outputting a list of symbols, it selects appropriate
ones and returns a list of them to the caller.

Nov 18 '08 #8
On Nov 18, 3:58*am, gor...@hammy.burditt.org (Gordon Burditt) wrote:
I need a function that give me *f* and *g*.
Is there any particular reason why this function should *NOT* also
give you "main", "printf", "exit", "getchar", etc. ?
Thanks for your reply.
I'm on Linux, and I want to get only the functions that I wrote them,

So you didn't write main()?
there is no problem, if any thing give me list of all function, I can
ignore some of them. Is there any library that work like *nm*?

You have the source code to nm, so go ahead and modify a copy of
it so instead of outputting a list of symbols, it selects appropriate
ones and returns a list of them to the caller.
I want do this on process, but nm do this on program, not process!
Nov 18 '08 #9
This is more appropriate for comp.unix.programmer; crossposted and
followups to there.

Ali Shirvani <aj*********@gmail.comwrites:
On Nov 18, 3:58*am, gor...@hammy.burditt.org (Gordon Burditt) wrote:
>I need a function that give me *f* and *g*.
>Is there any particular reason why this function should *NOT* also
give you "main", "printf", "exit", "getchar", etc. ?
>Thanks for your reply.
I'm on Linux, and I want to get only the functions that I wrote them,

So you didn't write main()?
>there is no problem, if any thing give me list of all function, I can
ignore some of them. Is there any library that work like *nm*?

You have the source code to nm, so go ahead and modify a copy of
it so instead of outputting a list of symbols, it selects appropriate
ones and returns a list of them to the caller.

I want do this on process, but nm do this on program, not process!
As far as I know, this is impossible. The names of your functions might
be stored in your program's binary, if it hasn't been stripped; but they
are certainly not loaded into your process's memory. By that time,
everything's been converted to raw addresses and the names are no longer
needed. So there is no way to get to them at runtime short of reading
the binary (which you could do with nm) or some other file where they
might be stored.

Why do you want to do this, anyway? Maybe there is a better way to
solve your underlying problem.
Nov 18 '08 #10
On 18 Nov, 05:12, Ali Shirvani <aj.shirv...@gmail.comwrote:
On Nov 18, 3:58 am, gor...@hammy.burditt.org (Gordon Burditt) wrote:
>I need a function that give me *f* and *g*.
>Is there any particular reason why this function should *NOT* also
>give you "main", "printf", "exit", "getchar", etc. ?
>Thanks for your reply.
>I'm on Linux, and I want to get only the functions that I wrote them,
So you didn't write main()?
>there is no problem, if any thing give me list of all function, I can
>ignore some of them. Is there any library that work like *nm*?
You have the source code to nm, so go ahead and modify a copy of
it so instead of outputting a list of symbols, it selects appropriate
ones and returns a list of them to the caller.

I want do this on process, but nm do this on program, not process!
I've looked at your three messages and am not clear: Do you want to
get these names from the source code - i.e. by scanning the C source -
or from the running process - i.e. to find out while executing what
functions are present?

--
James
Nov 18 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
33
by: abs | last post by:
Hi all. My list: <ul> <li id="a" onclick="show(this)">Aaaaaaaa</li> <li id="b" onclick="show(this)">Bbbbbbbb</li> <li id="c" onclick="show(this)">Cccccccc <ul> <li id="d"...
6
by: dam_fool_2003 | last post by:
Hai, I thank those who helped me to create a single linked list with int type. Now I wanted to try out for a void* type. Below is the code: #include<stdlib.h> #include<stdio.h>...
4
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; }; ...
9
by: TheOne | last post by:
Would anyone please point me to a list of reentrant C library functions? I want to know which C library functions are safe to use inside a signal handler across all platforms. Does GNU C library...
5
by: Little | last post by:
I have this program and I need to work on the test portion, which tests if a Val is in the list. It returns false no matter what could you look at the part and see what might need to be done to fix...
4
by: bejiz | last post by:
Hello, I have written a short program for practising linked lists. But there is surely something wrong for when I compile there is a unhandled exception and it does not print if I try to add more...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
6
by: Shawn Minisall | last post by:
I'm writing a game that uses two functions to check and see if a file called highScoresList.txt exists in the main dir of the game program. If it doesn, it creates one. That part is working fine. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.