How can we know the caller function's name?

后端 未结 10 1632
北海茫月
北海茫月 2020-12-02 10:26

In the C language, __FUNCTION__ can be used to get the current function\'s name. But if I define a function named a() and it is called

10条回答
  •  没有蜡笔的小新
    2020-12-02 11:18

    You can do it with a gcc builtin.

    void * __builtin_return_address(int level)

    The following way should print the immediate caller of a function a().

    Example:

    a() {
        printf ("Caller name: %pS\n", __builtin_return_address(0));
    }
    

提交回复
热议问题