473,471 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

function name printing

Can I print the current function name in c? something like __LINE__?

for e.g

can I do

printf( " the current file is %s : function is : %s and line # is
:%d\n", __FILE__, __FUNC__, __LINE__);
thanks
kumaravel.
Nov 14 '05 #1
7 1821
On Mon, 5 Jul 2004, Kumaravel wrote:

K>Can I print the current function name in c? something like __LINE__?
K>
K>for e.g
K>
K>can I do
K>
K>printf( " the current file is %s : function is : %s and line # is
K>:%d\n", __FILE__, __FUNC__, __LINE__);

__func__ is a a const char * and points to the current function name (for
C99). Gcc supported __FUNCTION__ and __PRETTY_FUNCTION__, but that's not
standard and has been deprecated.

harti
Nov 14 '05 #2

"Harti Brandt" <br****@dlr.de> a écrit dans le message de
news:20*******************@beagle.kn.op.dlr.de...
On Mon, 5 Jul 2004, Kumaravel wrote:

K>Can I print the current function name in c? something like __LINE__?
K>
K>for e.g
K>
K>can I do
K>
K>printf( " the current file is %s : function is : %s and line # is
K>:%d\n", __FILE__, __FUNC__, __LINE__);

__func__ is a a const char * and points to the current function name (for
C99). Gcc supported __FUNCTION__ and __PRETTY_FUNCTION__, but that's not
standard and has been deprecated.

harti


What was __PRETTY_FUNCTION__ ???

Weird name ... :-)
Nov 14 '05 #3
On Mon, 05 Jul 2004 04:20:18 -0700, Kumaravel wrote:
Can I print the current function name in c? something like __LINE__?
for e.g


yes, in C99 you can use the predefined identifier __func__

regards
zhan
Nov 14 '05 #4
On Mon, 5 Jul 2004, jacob navia wrote:

jn>
jn>"Harti Brandt" <br****@dlr.de> a écrit dans le message de
jn>news:20*******************@beagle.kn.op.dlr.de. ..
jn>> On Mon, 5 Jul 2004, Kumaravel wrote:
jn>>
jn>> K>Can I print the current function name in c? something like __LINE__?
jn>> K>
jn>> K>for e.g
jn>> K>
jn>> K>can I do
jn>> K>
jn>> K>printf( " the current file is %s : function is : %s and line # is
jn>> K>:%d\n", __FILE__, __FUNC__, __LINE__);
jn>>
jn>> __func__ is a a const char * and points to the current function name (for
jn>> C99). Gcc supported __FUNCTION__ and __PRETTY_FUNCTION__, but that's not
jn>> standard and has been deprecated.
jn>>
jn>> harti
jn>
jn>What was __PRETTY_FUNCTION__ ???

That gives you the complete function signature (including name space and
classes in C++).

harti
Nov 14 '05 #5
Kumaravel wrote:
Can I print the current function name in c? something like __LINE__?

for e.g

can I do

printf( " the current file is %s : function is : %s and line # is
:%d\n", __FILE__, __FUNC__, __LINE__);


#include <stdio.h>

#define FTRACE printf( " the current file is %s, " \
"function is %s, and line # is %d\n", \
__FILE__, __func__, __LINE__)

void foo1(void)
{
FTRACE;
}

void foo2(void)
{
FTRACE;
}

int main(void)
{
foo1();
foo2();
return 0;
}

[output]

the current file is a.c, function is foo1, and line # is 9
the current file is a.c, function is foo2, and line # is 14
Nov 14 '05 #6
jacob navia wrote:
"Harti Brandt" <br****@dlr.de> a écrit dans le message de
news:20*******************@beagle.kn.op.dlr.de...
__func__ is a a const char * and points to the current function name (for
C99). Gcc supported __FUNCTION__ and __PRETTY_FUNCTION__, but that's not
standard and has been deprecated.

What was __PRETTY_FUNCTION__ ???

Weird name ... :-)


Doubly off-topic: particular compiler (gcc) and wrong language (not C).
Used to print the function name as it appears in the source
(__FUNCTION__) or "in a language-specific way" (__PRETTY_FUNCTION__).
For C++, for example, __PRETTY_FUNCTION__ yields scoping information.
Nov 14 '05 #7
Harti Brandt <br****@dlr.de> wrote:
On Mon, 5 Jul 2004, Kumaravel wrote:

K>Can I print the current function name in c? something like __LINE__?
K>
K>for e.g
K>
K>can I do
K>
K>printf( " the current file is %s : function is : %s and line # is
K>:%d\n", __FILE__, __FUNC__, __LINE__);

__func__ is a a const char * and points to the current function name (for
C99).


Actually it is a const char [] containing the current function name
(so you can do "sizeof" on it, and take its address, etc.)
Nov 14 '05 #8

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

Similar topics

8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
12
by: Christopher J. Bottaro | last post by:
I want to get the name of the function from within the function. Something like: def myFunc(): print __myname__ >>> myFunc() 'myFunc' Really what I want to do is to easily strip off the...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
4
by: Ben Holness | last post by:
Hi all, I have a function, say: function printTable($Variables) { ?> <table> <tr><td>Your name is</td></tr> <tr><td>
54
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
5
by: viscroad | last post by:
I have a confusion when I do some practice, the code and output are as following, print 'In fun()....' In fun().... None <function fun at 0x00CC1270> In fun()....
6
by: SanPy | last post by:
The subject of this message might be a little cryptic, so here's an example of what I mean: def foo(): """doc string of foo""" print foo.__doc__ doc string of foo What I want to know is...
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);...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.