Writing a function pointer in c

后端 未结 3 2025
梦谈多话
梦谈多话 2021-01-18 18:25

I was recently reading a code, and found that a function pointer is written as :

int (*fn_pointer ( this_args ))( this_args )

I usually enc

3条回答
  •  鱼传尺愫
    2021-01-18 18:43

    From cdecl (which is a handy helper tool to decipher C declarations):

    int (*fn_pointer ( this_args1 ))( this_args2 )
    

    declare fn_pointer as function (this_args1) returning pointer to function (this_args2) returning int

    Hence the former is a function, that returns pointer to function, while the latter:

    return_type (*fn_pointer ) (arguments);

    is an ordinary "pointer to function".


    Read more about undestanding complex declarations from the Clockwise/Spiral Rule article.

提交回复
热议问题