Return function value of the function pointer

2020 I am confused by some of the code

#include <stdio.h>
   2 
   3 typedef char* (*CHARFUNC)();
   4 static char c = 'c';
   5 
   6 char* fun() {
   7     return &c;
   8 }
   9 
  10 void* func() {
  11     return fun;
  12 }   
  13 
  14 int main() {
  15     char* p = &c;
  16     CHARFUNC charfunc = (CHARFUNC)func();
  17     if (p == charfunc()) {
  18         printf("two pointer equals\n");
  19     }   
  20     else {
  21         printf("not equal\n");
         }
        return 0;
     }

This code can be compiled successfully in gcc, g ++ but not in the middle.

Guess you like

Origin www.cnblogs.com/lunar-ubuntu/p/12368925.html