Function Returning Itself

后端 未结 9 726
鱼传尺愫
鱼传尺愫 2020-11-27 04:59

Is it possible to declare some function type func_t which returns that type, func_t?

In other words, is it possible for a function to retur

9条回答
  •  天涯浪人
    2020-11-27 05:27

    A possible solution with structs:

    struct func_wrap
    {
        struct func_wrap (*func)(void);
    };
    
    struct func_wrap func_test(void)
    {
        struct func_wrap self;
    
        self.func = func_test;
        return self;
    }
    

    Compiling with gcc -Wall gave no warnings, but I'm not sure if this is 100% portable.

提交回复
热议问题