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. 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
"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 ... :-)
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
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
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
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.
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.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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"
...
|
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...
|
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>
|
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);
}
|
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()....
|
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...
|
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);...
|
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: 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,...
|
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |