473,809 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ 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 1847
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_FUNCTI ON__, but that's not
standard and has been deprecated.

harti
Nov 14 '05 #2

"Harti Brandt" <br****@dlr.d e> a écrit dans le message de
news:20******** ***********@bea gle.kn.op.dlr.d e...
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_FUNCTI ON__, but that's not
standard and has been deprecated.

harti


What was __PRETTY_FUNCTI ON__ ???

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.d e> a écrit dans le message de
jn>news:20***** **************@ beagle.kn.op.dl r.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_FUNCTI ON__, but that's not
jn>> standard and has been deprecated.
jn>>
jn>> harti
jn>
jn>What was __PRETTY_FUNCTI ON__ ???

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.d e> a écrit dans le message de
news:20******** ***********@bea gle.kn.op.dlr.d e...
__func__ is a a const char * and points to the current function name (for
C99). Gcc supported __FUNCTION__ and __PRETTY_FUNCTI ON__, but that's not
standard and has been deprecated.

What was __PRETTY_FUNCTI ON__ ???

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_FUNCT ION__).
For C++, for example, __PRETTY_FUNCTI ON__ yields scoping information.
Nov 14 '05 #7
Harti Brandt <br****@dlr.d e> 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
2805
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 _build_used(): .... y = x + 1 .... return x, y ....
12
6841
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 prefix of a function name and call another function. Like this:
1
2326
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" void main() {
11
2779
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 "YAHHH" .... result =
4
2357
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
24548
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
1155
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
2055
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 whether it is possible to call __doc__ against
9
1998
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); ...more phpcode..
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4333
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 we have to send another system

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.