确定运行时的函数名称 [英] determining function name in runtime

查看:48
本文介绍了确定运行时的函数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


有什么方法可以确定当前在

a流程中执行哪个功能?


例如我们可以使用__FILE__

找到文件名,使用__LINE__宏找到行号


simillarly是否有任何宏给出函数名称


谢谢shyam

解决方案



shyam写道:

大家好

有什么方法可以确定哪个功能当前正在进程中执行?


我认为你的意思是程序...

例如我们可以使用__FILE__
找到文件名,使用__LINE__宏找到行号




是的,它是__func __(注意前后双下划线)。


-

BR,Vladimir


----- BEGIN PGP签名消息-----

哈希:SHA1

shyam写道:

大家好

是否有任何方法可以确定当前正在执行哪个功能?



我认为你的意思程序...

例如我们可以使用__FILE__
找到文件名和使用__LINE__宏的行号

simillarly是否有任何宏给出函数名称



是的,我t'的__func__(注意前后双下划线)。




注意:与__FILE__和__LINE__不同,__ func__不是宏,而是

本地(到函数)范围的预定义标识符。


因此,

char * where_I_am ="我在线 __LINE__" \ n";

可以使用,但

char * where_I_am ="我正在使用 __func__" \ n" ;;

不会。


OTOH,

printf(我在线% d在函数%s \ n",__ LINE __,__ func__);

将起作用。

- -


Lew Pitcher,IT专家,企业技术解决方案,

企业技术解决方案,道明银行金融集团


(此处表达的意见是我自己的,而不是我的雇主'' s)

-----开始PGP签名-----

版本:GnuPG v1.4.2(MingW32)

评论:将GnuPG与Mozilla一起使用 - http://enigmail.mozdev.org


iD8DBQFEBwFDagVFX4UWr64RAlQdAJ9XT4qQS65GzFFRPO0RDF qxskDA + wCdGWGd

evG1lEWtpMvGxVdvP / Y97RM =

= vy6r

----- END PGP SIGNATURE-- ---




" Lew Pitcher" <乐********* @ tdsecurities.com>在消息中写道

news:8j ******************* @ news20.bellglobal.com ..。

-----开始PGP签名消息-----
哈希:SHA1

Vladimir S. Oka写道:
-snip


,它是__func __(注意前后双下划线)。
注意:与__FILE__和__LINE__不同,__ func__不是宏,而是
预定义的本地标识符(对于函数) )范围。

因此,
char * where_I_am =我在线 __LINE__" \ n";
会有效,但是
char * where_I_am ="我正在使用 __func__" \ n" ;;
不会。

OTOH,
printf(我在函数%s \ n中的行%d,__ LINE__, __func__);
将起作用。




我猜,__ func__是C99功能?

< OT> (这意味着我不能将它与我的编译器msvc 6.0一起使用)。< OT>


-

MrG {DRGN}


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

解决方案


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}


这篇关于确定运行时的函数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆