473,772 Members | 3,665 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
12 2796
On 2006-03-02, Lew Pitcher <Le*********@td securities.com> wrote:

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.


That's because that's not the right place to look
http://www.open-std.org/jtc1/sc22/wg...onaleV5.10.pdf

lines 29-31 on page 50 [PDF page 57] read as follows:

A new feature of C99: C99 introduces predefined identifiers, which have
block scope (as distinct 30 from predefined macros which have file
scope), and one such predefined identifier, __func__, which allows the
function name to be used at execution time.

That seems to be saying that the reason is because a macro has file
scope, and thus couldn't have a different value on different lines
unless undefined and redefined by the user.

Note, however, that string literal concatenation takes place in phase 6,
whereas semantic analysis [which is when { } becomes a block scope, etc]
is phase 7.
Mar 2 '06 #11
On Thu, 02 Mar 2006 21:48:10 +0000, Jordan Abel wrote:
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"
Micro correction: swap %s and %d (or __LINE__ and __func__ below)
#define WHERE_ARGS __LINE__,__func __
#endif

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


--
Ben.
Mar 3 '06 #12
Jordan Abel <ra*******@gmai l.com> writes:
On 2006-03-02, Lew Pitcher <Le*********@td securities.com> wrote:

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.


That's because that's not the right place to look
http://www.open-std.org/jtc1/sc22/wg...onaleV5.10.pdf

lines 29-31 on page 50 [PDF page 57] read as follows:

A new feature of C99: C99 introduces predefined identifiers, which have
block scope (as distinct 30 from predefined macros which have file
scope), and one such predefined identifier, __func__, which allows the
function name to be used at execution time.

That seems to be saying that the reason is because a macro has file
scope, and thus couldn't have a different value on different lines
unless undefined and redefined by the user.


__LINE__ has a different value on different lines, and the
preprocessor has no problem handling that.

__func__ isn't a macro because making it one would have required the
preprocessor (more precisely, translation phase 4) to understand more
of the language grammar than is currently required.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #13

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
11954
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
9620
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
9454
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
10261
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...
1
10038
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
9912
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
8934
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...
0
6715
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
5354
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...
3
2850
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.