473,387 Members | 1,548 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,387 software developers and data experts.

finding the name of the function

GVK
Hi,
I've written a piece of network code in C. I'm pritting lots of
debugging information, just in case the program is screwed :) Is there
any built-in function that gives the name of the function from which it
is called? For example,

int foo()
{
print_function_name(); /* some built-in system call */
}

should output the name as "foo()" or somewhat similarly. I've been
coding in C for almost 2 and half years but never used such a function
till now. Any help is appreciated.

regards,
GVK
--
Happy Hacking!!!
Nov 14 '05 #1
5 1115
GVK <va******@students.iiit.net> spoke thus:
I've written a piece of network code in C. I'm pritting lots of
debugging information, just in case the program is screwed :) Is there
any built-in function that gives the name of the function from which it
is called? For example,


There is no standard one AFAIK, but __FILE__ and __LINE__ can provide
a decent approximation.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
GVK <va******@students.iiit.net> writes:
I've written a piece of network code in C. I'm pritting lots
of debugging information, just in case the program is screwed :) Is
there any built-in function that gives the name of the function from
which it is called? For example,


C99 offers the __func__ predefined identifier. GCC offers the
nonstandard __FUNCTION__.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
Nov 14 '05 #3
GVK wrote:
I've written a piece of network code in C. I'm pritting lots of
debugging information, just in case the program is screwed :) Is there
any built-in function that gives the name of the function from which it
is called?


There's no way to do that in C89, but C99 defines __func__, an array
containing the name of the current function:

int foo()
{
puts(__func__);
}

Some compilers provide extensions to do the same thing; for example,
GCC has __FUNCTION__ and __PRETTY_FUNCTION__, which are similar to
__func__.

(I'd like to propose this as an additional FAQ.)

Jeremy.
Nov 14 '05 #4
GVK
> GVK wrote:

I've written a piece of network code in C. I'm pritting lots of
debugging information, just in case the program is screwed :) Is there
any built-in function that gives the name of the function from which it
is called?


Thanks a lot to all the guys who took time to read my doubt. I got it
working and thanks again to all the gurus who replied. __FUNCTION__ works.

GVK

--
Happy Hacking!!!
Nov 14 '05 #5
in comp.lang.c i read:
GVK <va******@students.iiit.net> writes:

I've written a piece of network code in C. I'm pritting lots
of debugging information, just in case the program is screwed :) Is
there any built-in function that gives the name of the function from
which it is called? For example,


C99 offers the __func__ predefined identifier. GCC offers the
nonstandard __FUNCTION__.


recent versions of most compilers that had something non-standard also now
provide the newer, standard identifier, including gcc.

--
a signature
Nov 14 '05 #6

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

Similar topics

5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
10
by: tshad | last post by:
I have a Datagrid with a column: <asp:HyperLinkColumn DataTextField="JobTitle" DataNavigateUrlField="PositionID" DataNavigateUrlFormatString="AddNewPositions.aspx?PositionID={0}"...
13
by: athiane | last post by:
I want a way to parse out all function names that appear in a couple of C files. When the parsing logic finds a function name in a file, it should print out the Function name, line number and file...
2
by: lcaamano | last post by:
We have a tracing decorator that automatically logs enter/exits to/from functions and methods and it also figures out by itself the function call arguments values and the class or module the...
19
by: Kirk Strauser | last post by:
Given a class: how can I find its name, such as: 'foo' I'm writing a trace() decorator for the sake of practice, and am trying to print the name of the class that a traced method belongs...
3
by: Rico | last post by:
Hello, I have a generic process that logs errors from different sources. When I call this code, I'd like to also submit the name of the function or sub that is raising the error without having...
3
by: Francesco Guerrieri | last post by:
Hi, Today I've been thinking a bit about the "python internals". Inspired by this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062 I found out a little problem which...
9
by: Erwin Moller | last post by:
Hi all, Is it possible (PHP5.2) to find the name of a variable used in the caller of a function from within the function itself? Or to be more clear: ...php code.. $result = foo($abc);...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
5
by: bharathreddy | last post by:
How to find the size of a folder using C# code? step1: Here take the folder which u want to find the size, then pass that folder to the recursive function name FolderSize!. DirectoryInfo...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.