473,765 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determining function name in runtime

Hi all

is there any way the determine which function currently is executing in
a process ?

For example we can find the file name using __FILE__
and line number using __LINE__ macros

simillarly is there any macro which gives the function name

thanks shyam

Mar 2 '06 #1
12 2794

shyam wrote:
Hi all

is there any way the determine which function currently is executing in
a process ?
I assume you mean program...

For example we can find the file name using __FILE__
and line number using __LINE__ macros

simillarly is there any macro which gives the function name


Yes, and it's __func__ (note double underscores before and after).

--
BR, Vladimir

Mar 2 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vladimir S. Oka wrote:
shyam wrote:
Hi all

is there any way the determine which function currently is executing in
a process ?


I assume you mean program...
For example we can find the file name using __FILE__
and line number using __LINE__ macros

simillarly is there any macro which gives the function name


Yes, and it's __func__ (note double underscores before and after).


Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Thus,
char *where_I_am = "I am at line " __LINE__ "\n";
would work, but
char *where_I_am = "I am in function " __func__ "\n";
would not.

OTOH,
printf("I am at line %d in function %s\n",__LINE__, __func__);
will work.
- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEBwFDagV FX4UWr64RAlQdAJ 9XT4qQS65GzFFRP O0RDFqxskDA+wCd GWGd
evG1lEWtpMvGxVd vP/Y97RM=
=vy6r
-----END PGP SIGNATURE-----
Mar 2 '06 #3

"Lew Pitcher" <Le*********@td securities.com> wrote in message
news:8j******** ***********@new s20.bellglobal. com...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vladimir S. Oka wrote: -snip

, and it's __func__ (note double underscores before and after).
Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Thus,
char *where_I_am = "I am at line " __LINE__ "\n";
would work, but
char *where_I_am = "I am in function " __func__ "\n";
would not.

OTOH,
printf("I am at line %d in function %s\n",__LINE__, __func__);
will work.


Let me guess, __func__ is a C99 feature?
<OT> (which means I can't use it with my compiler msvc 6.0).<OT>

--
MrG{DRGN}
Mar 2 '06 #4

MrG{DRGN} wrote:
"Lew Pitcher" <Le*********@td securities.com> wrote in message
news:8j******** ***********@new s20.bellglobal. com...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vladimir S. Oka wrote:

-snip

, and it's __func__ (note double underscores before and after).

Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Thus,
char *where_I_am = "I am at line " __LINE__ "\n";
would work, but
char *where_I_am = "I am in function " __func__ "\n";
would not.

OTOH,
printf("I am at line %d in function %s\n",__LINE__, __func__);
will work.


Let me guess, __func__ is a C99 feature?
<OT> (which means I can't use it with my compiler msvc 6.0).<OT>


Yes it is.
<OT>I know nothing about M$VC, but it may provide it as an
extension?<OT>

Mar 2 '06 #5
Ico
Lew Pitcher <Le*********@td securities.com> wrote:
Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Is there a reason why __func__ is not a macro ?

--
:wq
^X^Cy^K^X^C^C^C ^C
Mar 2 '06 #6

Ico wrote:
Lew Pitcher <Le*********@td securities.com> wrote:
Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Is there a reason why __func__ is not a macro ?


It is easy for the preprocessor to know the current file and line.
However, it can not known the function name (even it can not known what
is a function) if it doesn't knowns C syntax (and the preprocessor
doesn't).

Mar 2 '06 #7
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ico wrote:
Lew Pitcher <Le*********@td securities.com> wrote:
Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Is there a reason why __func__ is not a macro ?


My copy of the draft C99 standard doesn't give a reason.

My /guess/ is that __FILE__ and __LINE__ can be implemented as macros
because they do not require any interpretation of the C code (they are
strictly derived from the mechanics of reading the source files).

OTOH, __func__ requires the compiler's interpretation of the code in
order to work, so it cannot be implemented in the same manner as __FILE_
and __LINE__.
- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEByGZagV FX4UWr64RAjQJAJ 9unyR7P+JPi14Yw Ci+eKaYF+VeMgCg s0N/
yRzUKfTTmLVMySm RWJUv6us=
=KubY
-----END PGP SIGNATURE-----
Mar 2 '06 #8
"tmp123" <tm****@menta.n et> writes:
Ico wrote:
Lew Pitcher <Le*********@td securities.com> wrote:
Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Is there a reason why __func__ is not a macro ?


It is easy for the preprocessor to know the current file and line.
However, it can not known the function name (even it can not known what
is a function) if it doesn't knowns C syntax (and the preprocessor
doesn't).


s/doesn't/might not/

Several implementations have provided such a macro. While they /may/
have been handled differently from other macros (I don't actually
know), they were still handled as string literals, and thus you could
make use of the concatenation feature, etc.

But I think the reason you give above is at least why the standard
didn't want to /require/ __func__ to be a macro (and so they required
it to be something else).

-Micah
Mar 2 '06 #9
On 2006-03-02, MrG{DRGN} <Ia****@here.co m> wrote:

"Lew Pitcher" <Le*********@td securities.com> wrote in message
news:8j******** ***********@new s20.bellglobal. com...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vladimir S. Oka wrote:

-snip

, and it's __func__ (note double underscores before and after).

Note: Unlike __FILE__ and __LINE__, __func__ is not a macro, but a
predefined identifier of local (to the function) scope.

Thus,
char *where_I_am = "I am at line " __LINE__ "\n";
would work, but
char *where_I_am = "I am in function " __func__ "\n";
would not.

OTOH,
printf("I am at line %d in function %s\n",__LINE__, __func__);
will work.


Let me guess, __func__ is a C99 feature?
<OT> (which means I can't use it with my compiler msvc 6.0).<OT>


No, but i have a suggestion:

#if __STDC_VERSION_ _ < 199901l
#define WHERE_FMT __FILE__ ":%d"
#define WHERE_ARGS __LINE__
#else
#define WHERE_FMT __FILE__ ":%s:%d"
#define WHERE_ARGS __LINE__,__func __
#endif

fprintf(stderr, "Line printed to stderr at "WHERE_FMT"\n", WHERE_ARGS);

will print file.c:function :42 on c99 systems, file.c:42 on others.
Mar 2 '06 #10

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

Similar topics

9
4964
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
1
5411
by: RWC | last post by:
Hi Folks, I'm looking for a way to determine if the client machine has access installed and if so, what version. The reason I need this is to determine (programatically) if the Access Runtime is required to be installed and if not, which version of the program database needs to be installed with the current version of Access. (hope that makes sense). If anyonoe could point me in the right direction, I'd really appreciate it.
0
1241
by: Stephen Nesbitt | last post by:
All: Here's my implementation problem. I have a base class which has the responsibility for providing entry into the logging system. Part of the class responsibility is to ensure that lagger names are consistent. For all intents and purposes this class should be considered abstract and will always be subclassed. What I want to do is the following: - allow the logger name to set explicitly. I've accomplished this by
5
2995
by: Lyn | last post by:
Is there any way of determining in VBA the name and arguments of the currently executed procedure? To assist in debugging, I would like to be able to trace the procedures as they are executed. Then, when it crashes with Access's usual unhelpful error messages, at least I will be able to determine in which procedure it happened. What I had in mind was something like this, inserted as the first statement in every procedure during...
1
1981
by: Susan Bricker | last post by:
Greetings. I am trying to position opened forms so that they are cascaded on the screen. I have discovered the movesize action (for the DoCmd) and Move property of a form (for Acc 2002/2003). However, if the application is opened up on different monitors (e.g.; 17" or 19"), the relative location of the opened form is not the same (i.e.; on the bigger monitor the opened form is too far over to the right and too high). What I want to...
0
1692
by: CTDev Team | last post by:
Hi, We are using Exchange Server 5.5, and have applications written in VB6 and C# that read and process emails. We are experiencing intermittent errors similar to C# Application System.Runtime.InteropServices.COMException (0x80004005): The client
2
3646
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
1
983
by: roddles | last post by:
Hi I need to at runtime determine the name of the function I am currently in, and the namespace of the class the function is executing from. I need this information for some logging routines i am writing and I do not want to have to hard code everything Can someone tell me which classes i need to use in order to get this information. Some sample code snippets would be very helpful if available Cheer Rod.
7
11953
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return "DirectoryEntry" objects within the path that I specify (either using the DirectoryEnrtry.Children or using the DirectorySearcher class) and all started well and dandy! Now the problem; some of the properties of the DirectoryEntry objects being...
0
9568
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
9404
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
10007
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...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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
5277
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.