Get the latest tech news
C "clockwise/spiral" rule to understand declarations
There is a technique known as the ``Clockwise/Spiral Rule'' which enables any C programmer to parse in their head any C declaration! There are three simple steps to follow: +-------+ | +-+ | | ^ | | char *str[10]; ^ ^ | | | +---+ | +-----------+Question we ask ourselves: What is str? ``str is an... ``str is an array 10 of...
There is a technique known as the ``Clockwise/Spiral Rule'' which enables any C programmer to parse in their head any C declaration! 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. Finally we continue and the only thing left is the word `void', so the final complete definition for signal is:``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)''
Or read this on Hacker News