How to understand this define

前端 未结 6 2494
-上瘾入骨i
-上瘾入骨i 2021-02-19 23:19

Nowadays , i was reading the APUE.and i found the function defined as below:

void (*signal(int signo, void (*func)(int)))(int);

i was confused,

6条回答
  •  名媛妹妹
    2021-02-19 23:40

    The Clockwise Spiral rule will help: http://c-faq.com/decl/spiral.anderson.html

    There are three simple steps to follow:

    Starting with the unknown element, move in a spiral/clockwise direction; when ecountering the following elements replace them with the corresponding english statements:

    [X] or [] => Array X size of... or Array undefined size of...

    (type1, type2) => function passing type1 and type2 returning...

    • => pointer(s) to...

    Keep doing this in a spiral/clockwise direction until all tokens have been covered. Always resolve anything in parenthesis first!

    See "Example #3: The 'Ultimate'", which is pretty much exactly what you are asking for:

    "signal is a function passing an int and a pointer to a function passing an int returning nothing (void) returning a pointer to a function passing an int returning nothing (void)"

提交回复
热议问题