How can we know the caller function's name?

后端 未结 10 1629
北海茫月
北海茫月 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:04

    #include 
    #include 
    

    #define FUNCTION_NAME(FUNCTION) printf("FUNCTION=%s \r\n", #FUNCTION);

    int a() {
      printf("A function call");
    }
    
    int b() {
      printf("B function call");
    }
    
    int main(){
    FUNCTION_NAME(a);
    FUNCTION_NAME(b);
    return 0;
    

    }

提交回复
热议问题