如何知道哪个函数调用了另一个函数 [英] How to know what function called another

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

问题描述

我想知道是否有任何方法可以知道当前正在执行的函数在哪里被调用,即在哪个文件和行中.我正在使用 C 语言,我正在寻找类似于 __FUNCTION__、__LINE__ 或 __FILE__ 宏的东西.

I wanna know if there is any way to know where the function currently in execution was called, this is, in what file and line. I'm using C language, and I'm looking for something similar to __FUNCTION__, __LINE__ or __FILE__ macros.

推荐答案

重命名你的函数

void Function(param1)
{
}

void Function_debug(param1, char * file, char * func, unsigned long line)
{
}

然后#define这样的宏:

Then #define a macro like this:

#define Function(param1) Function_debug(param1, __FILE__, __FUNCTION__, __LINE__)

这篇关于如何知道哪个函数调用了另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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