获得在C调用函数的名称(不使用preprocessor) [英] Getting the name of the calling function in C (without using the preprocessor)

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

问题描述

我在想,如果有发现的一种方式这函数调用在C当前功能(在运行时)。

I was wondering if there is a way of finding which function called the current function (at runtime) in C.

我知道你可以使用 __在GCC功能__ ,但有没有办法不使用C preprocessor?

I know you could use __FUNCTION__ in gcc, but is there a way without using the C preprocessor?

大概没有。

干杯

推荐答案

没有,没有。 C是不是一个特别内向的语言 - 像一个函数的名字的事情(或调用堆栈件)根本不提供任何理智的方式运行。

No, there isn't. C isn't a particularly introspective language - things like the name of a function (or pieces of your call stack) simply aren't available at runtime in any sane fashion.

如果由于某种原因,你正在寻找大量的工作非常少的好处,那么你可以使用调试符号建立你的节目,你可以写堆栈行走和调试符号查找code。然后,你也许能发现这一点的飞行。但要小心,因为你在调试信息看到这些符号将与类型信息加以装饰,如果你有任何C ++参与。

If, for some reason, you are looking for a lot of work for very little benefit, then you can build your programs with debug symbols, and you can write stack-walking and debug symbol lookup code. Then you might be able to find this out on the fly. But be careful, because the symbols you'll see in the debug info will be decorated with type info if you've got any C++ involved.

您已经标记了这个帖子的gcc,所以相关的细节是可用的,然而,这落入不推荐和不保证编译器版本之间的相同的领土。

You've tagged this post gcc, so the relevant details ARE available, however this falls into the 'not recommended' and 'not guaranteed to be the same between compiler versions' territory.

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

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