linux@ubuntu:~/linux_c$ cat example.c 
#include <stdio.h>




int main(void)
{
printf("hi main=%s %s\n",__FUNCTION__,__PRETTY_FUNCTION__);
printf("hi main=%s %s\n",__FUNCTION__,__func__);
return 0;
}


linux@ubuntu:~/linux_c$ cat test.cpp 
#include <stdio.h>
extern "C" {
     extern int printf (const char *, ...);
     }
     
     
     class a {
      public:
       void sub (int i)
         {
           printf ("__FUNCTION__ = %s\n", __FUNCTION__);
           printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
         }
     };
     
     int
     main (void)
     {
       a ax;
       ax.sub (0);
       return 0;
     


linux@ubuntu:~/linux_c$ g++ test.cpp -o dd

linux@ubuntu:~/linux_c$ ls -l
total 28
-rwxrwxr-x 1 linux linux 8324 Sep 29 11:21 a.out
-rwxrwxr-x 1 linux linux 7285 Sep 29 11:24 dd
-rw-rw-r-- 1 linux linux  162 Sep 29 11:19 example.c
-rw-rw-r-- 1 linux linux  401 Sep 29 11:24 test.cpp
linux@ubuntu:~/linux_c$ ./a.out
hi main=main main
hi main=main main
linux@ubuntu:~/linux_c$ ./dd 
__FUNCTION__ = sub
__PRETTY_FUNCTION__ = void a::sub(int)
linux@ubuntu:~/linux_c$ gcc -g example.c
linux@ubuntu:~/linux_c$ ./a.out 
hi main=main main
hi main=main main
linux@ubuntu:~/linux_c$ g++ -g example.c
linux@ubuntu:~/linux_c$ ./a.out 
hi main=main int main()

hi main=main main


In C, __PRETTY_FUNCTION__ is yet another name for __func__. However, in C++, __PRETTY_FUNCTION__ contains the type signature of the function as well as its bare name


https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

Logo

更多推荐