Live data from Hacker News

The "Clockwise/Spiral Rule" in C

c-faq.com

11–20 of 49 posts

Re: The "Clockwise/Spiral Rule" in C

#15

The "spiral rule" makes for pretty pictures, but unfortunately it isn't correct. One simple example: int *foo[3][4]; The spiral rule would have us read this as "foo is an array [3] of pointers to array [4] of int". What it actually is is "foo is an array [3] of arrays [4] of pointers to int". The correct rule* for parsing declarations is "Start from the thing being declared, and read right until you hit a closing par…

I think it works if you treat all the [] as a single token. foo is a 3x4 two dimensional array of pointers to int.

Re: The "Clockwise/Spiral Rule" in C

#17

The "spiral rule" makes for pretty pictures, but unfortunately it isn't correct. One simple example: int *foo[3][4]; The spiral rule would have us read this as "foo is an array [3] of pointers to array [4] of int". What it actually is is "foo is an array [3] of arrays [4] of pointers to int". The correct rule* for parsing declarations is "Start from the thing being declared, and read right until you hit a closing par…

I think it works if you treat all the [] as a single token. foo is a 3x4 two dimensional array of pointers to int.

You can construct a rule along those lines that would work (though just taking all the [] at once doesn't suffice), but it ends up being precisely equivalent to the right-left rule, so I don't really see the point.

Re: The "Clockwise/Spiral Rule" in C

#18

The "spiral rule" makes for pretty pictures, but unfortunately it isn't correct. One simple example: int *foo[3][4]; The spiral rule would have us read this as "foo is an array [3] of pointers to array [4] of int". What it actually is is "foo is an array [3] of arrays [4] of pointers to int". The correct rule* for parsing declarations is "Start from the thing being declared, and read right until you hit a closing par…

I think it works if you treat all the [] as a single token. foo is a 3x4 two dimensional array of pointers to int.

But its not, there are no two dimensional arrays. There are arrays of arrays.

Re: The "Clockwise/Spiral Rule" in C

#19

Earlier quoted context omitted.

I think it works if you treat all the [] as a single token. foo is a 3x4 two dimensional array of pointers to int.

But its not, there are no two dimensional arrays. There are arrays of arrays.

Yes, but does it matter? We can call that a 2D array.
Post reply on HN