调用函数名称 [英] Calling function name

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

问题描述

有没有办法让某个功能知道谁给他打电话?

Is there an way for a function to know who called him ?

推荐答案

最新的gcc,vs.net支持__FUNCTION__,使用它


#include< stdio.h>


int func1(char * str)

{

printf(由%s \ nn,str调用);

返回0;

}


int main(无效)

{

func1(__ FUNCTION__);

返回0;

}


Saroj写道:
lastest gcc ,vs.net support __FUNCTION__, use it

#include <stdio.h>

int func1(char * str)
{
printf("called by %s\n",str);
return 0;
}

int main(void)
{
func1(__FUNCTION__);
return 0;
}

Saroj wrote:
有没有办法让函数知道是谁打电话给他?
Is there an way for a function to know who called him ?





baumann @ pan写道:


baumann@pan wrote:
最新的gcc,vs.net支持__FUNCTION__,使用它

#include< stdio.h>

int func1(char * str)
{/> printf("%s \ n" ,str);
返回0;
}
int main(无效)
{
func1(__ FUNCTION__);
返回0;
}

Saroj写道:
lastest gcc ,vs.net support __FUNCTION__, use it

#include <stdio.h>

int func1(char * str)
{
printf("called by %s\n",str);
return 0;
}

int main(void)
{
func1(__FUNCTION__);
return 0;
}

Saroj wrote:
有没有办法让某个函数知道是谁打电话给他?
Is there an way for a function to know who called him ?




还有另一种方式吗?

这种方式如下:


int main()

{

func1(" main"); //但需要将func1(char *)变为

// func1(const char *)

返回0;

}



Is there another way?
This way look like:

int main()
{
func1("main"); // but need to chage func1(char*) to
// func1(const char*)
return 0;
}




#if DISPLAY_CALLER

#define func1_hooked()func1(__ FUNCTION__)

#else

#define func1_hooked()func1(0)

#endif


now
<主要是


int main(无效)

{

func1_hooked();

返回0;

}

baumann @ pan写道:

#if DISPLAY_CALLER
#define func1_hooked() func1(__FUNCTION__)
#else
#define func1_hooked() func1(0)
#endif

now

in main,

int main(void)
{
func1_hooked();
return 0;
}
baumann@pan wrote:
最新的gcc,vs.net支持__FUNCTION__,使用它

#include< stdio.h>

int func1(char * str)
{
printf("%s \ n",str);
返回0;
}
int main(void)
{
func1(__ FUNCTION__);
返回0;
}

Saroj写道:
lastest gcc ,vs.net support __FUNCTION__, use it

#include <stdio.h>

int func1(char * str)
{
printf("called by %s\n",str);
return 0;
}

int main(void)
{
func1(__FUNCTION__);
return 0;
}

Saroj wrote:
有没有办法让函数知道谁给他打电话?
Is there an way for a function to know who called him ?





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

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