How can we know the caller function's name?

后端 未结 10 1627
北海茫月
北海茫月 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条回答
  •  猫巷女王i
    2020-12-02 11:27

    If you're only after knowing where you were for logging/debug purposes you can use a macro to avoid __func__ giving the name of your logging/debug function but of the function calling it.

    Being in a macro will not result in a change to __func__ but will "feel" like using a function.

    e.g.

    #define LOG(s, data...) log("%s: "s, __function__, ## data)
    

提交回复
热议问题