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 12 2706
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
-----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
iD8DBQFEBwFDagVFX4UWr64RAlQdAJ9XT4qQS65GzFFRPO0RDF qxskDA+wCdGWGd
evG1lEWtpMvGxVdvP/Y97RM=
=vy6r
-----END PGP SIGNATURE-----
"Lew Pitcher" <Le*********@tdsecurities.com> wrote in message
news:8j*******************@news20.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}
MrG{DRGN} wrote: "Lew Pitcher" <Le*********@tdsecurities.com> wrote in message news:8j*******************@news20.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>
Lew Pitcher <Le*********@tdsecurities.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
Ico wrote: Lew Pitcher <Le*********@tdsecurities.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).
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ico wrote: Lew Pitcher <Le*********@tdsecurities.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
iD8DBQFEByGZagVFX4UWr64RAjQJAJ9unyR7P+JPi14YwCi+eK aYF+VeMgCgs0N/
yRzUKfTTmLVMySmRWJUv6us=
=KubY
-----END PGP SIGNATURE-----
"tmp123" <tm****@menta.net> writes: Ico wrote: Lew Pitcher <Le*********@tdsecurities.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
On 2006-03-02, MrG{DRGN} <Ia****@here.com> wrote: "Lew Pitcher" <Le*********@tdsecurities.com> wrote in message news:8j*******************@news20.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.
On 2006-03-02, Lew Pitcher <Le*********@tdsecurities.com> wrote: Ico wrote: Lew Pitcher <Le*********@tdsecurities.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.
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.
Jordan Abel <ra*******@gmail.com> writes: On 2006-03-02, Lew Pitcher <Le*********@tdsecurities.com> wrote: Ico wrote: Lew Pitcher <Le*********@tdsecurities.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_Keith) 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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?
|
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...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |