Pointer to current function

前端 未结 4 1278
难免孤独
难免孤独 2020-12-19 13:06

Is there any way to get a pointer to the current function, maybe through gcc extensions or some other trickery?

Edit I\'m curious whether it is poss

4条回答
  •  生来不讨喜
    2020-12-19 13:25

    Looks like this has been asked before on SO, here is an interesting answer that I have not tested:

    Get a pointer to the current function in C (gcc)?

    Anyway, there are some interesting extensions, with gcc extensions, are you familiar with the __FUNCTION__ macro?

    See what you think about this (this will just get you a string with the name of the function:

    #include 
    #include 
    
    
    void printme(char *foo)
    {
        printf("%s says %s\n", __FUNCTION__, foo);
    }
    
    
    int main(int argc, char *argv[])
    {
    
        printme("hey");
    
        return 0;
    }
    

提交回复
热议问题