3 ms·
The correct rule is that postfix operators bind more tightly than unary. Declarations imitate use, so in declarators, we can regard the unary star and the postf
by kazinator 8y ago
The correct rule is that postfix operators bind more tightly than unary. Declarations imitate use, so in declarators, we can regard the unary star and the postfix () and [] as unary and postfix operators. So "star star a [][]" is "star star (a [] [])".
To apply the spiral rule in these cases, we have to collapse together the chained unary and postfix operators so that the spiral traverses them as one clump:
// +--------+
// | |
// | |
int *** aa[2][3][4];
// ^ | v |
// | | | |
// | | | |
// +----+ +----+
"aa is an (array of array of array) of (pointer to pointer to pointer) to int".
The spiral only makes additional iterations when precedence parentheses are present. Each level of parentheses has its own postfix-unary round trip:
// +----------+
// | +----+ |
// | | | |
// | | | |
int **(* aa[2])[3][4];
// ^ | | v | |
// | | | | | |
// | | | | | |
// +----+ | +--+ |
// +--------+