Is it possible to get the caller's name in C ?

Way79 2004-08-20 06:51:20
Great thanks if can help,
...全文
132 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
dhfly 2004-08-20
  • 打赏
  • 举报
回复
RTTI
pacman2000 2004-08-20
  • 打赏
  • 举报
回复
好像是没有的啊。
huangyang88 2004-08-20
  • 打赏
  • 举报
回复
试试__FILE__ __LINE__
darkstar21cn 2004-08-20
  • 打赏
  • 举报
回复
偶比较笨,只是来看看是否有答案。
qwertasdfg123 2004-08-20
  • 打赏
  • 举报
回复

有些编译器支持使用__func__来取得当前的函数的名称。
bukaixindezhu 2004-08-20
  • 打赏
  • 举报
回复
gz
sharkhuang 2004-08-20
  • 打赏
  • 举报
回复
调用者啊.用宏在调用的__FILE__ __LINE__
sharkhuang 2004-08-20
  • 打赏
  • 举报
回复
__FUNCTION__
winstonch 2004-08-20
  • 打赏
  • 举报
回复
没试试FILE宏?
expert2000 2004-08-20
  • 打赏
  • 举报
回复
可以在log中显示。
  • 打赏
  • 举报
回复
DEBUG版应该是可以的,调试信息里应该有的,不过Release就肯定不行了
qwertasdfg123 2004-08-20
  • 打赏
  • 举报
回复

如果依赖编译器来给出被调用的子函数名,那可能是不行的。

楼主可以通过传递函数名称来实现这种要求。

bianliuwei 2004-08-20
  • 打赏
  • 举报
回复
好像不太可能,被调用者相当于服务器,它是不可能判断出客户的名称的.只是小弟观点,欢迎指教!
yjh1982 2004-08-20
  • 打赏
  • 举报
回复
no possible
njSeeWhy 2004-08-20
  • 打赏
  • 举报
回复
这个基本上不太可能。因为调用者的名字是用来给人看的,而生成可执行代码的是编译器,编译器完全可以在编译时把函数的名字改掉,所以除非你自己在某个地方已字符串的形式存储了函数的名称,否则仅仅想通过运行时的信息来获得调用者的名字是比较难的。
Way79 2004-08-20
  • 打赏
  • 举报
回复
from a subroutine, getting the name of the function the subroutine was called from
loveyou19840806 2004-08-20
  • 打赏
  • 举报
回复
我不知道你想问什么东西?
Way79 2004-08-20
  • 打赏
  • 举报
回复
Of course gdb get the routine name from the symbol table. But I don't know how can it get the call stack. Maybe I should read the gdb code first :P

As I known , some commercial API has realized it
njSeeWhy 2004-08-20
  • 打赏
  • 举报
回复
gdb应该是通过读取编译器生成的符号表来获取函数名称的吧,直接在程序中程序中可能不行。楼主是否能把需求说得更清楚些,比如有哪些可利用的条件,又有哪些限制等。
Way79 2004-08-20
  • 打赏
  • 举报
回复
even in no-debug binary, the routine name info is always there.

if you write a simple C program , compile it as default (no debug), then use gdb to open it. You can get the call stack displayed with routine name , although there is no source code info.

I think there must a way like what gdb do , or we can simply use the gdb lib to get the call stack.

加载更多回复(2)

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧