News for hackers. Stuff that matters.
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @09:57PM (#22681288)
What about this do you find disagreeable? http://c-faq.com/decl/spiral.anderson.html
Re:Zig cc: A drop-in replacement for GCC/Clang by palotasb on Wednesday March 25, 2020 @04:16AM (#22682832)
The spiral rule works if "pointer to" and "function returning"/"array of" alternate but it breaks if they don't, i.e., if you have arrays of arrays or pointers to pointers.

    int** arr1_of_arr2_of_arr3_of_ptr_to_ptr_to_int[1][2][3]
In this case, spiraling between [1], ×, [2], ×, [3], int is obviously wrong, the correct reading order is [1], [2], [3], ×, ×, int. (Edit: read × = *)

The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

Re:Zig cc: A drop-in replacement for GCC/Clang by diegoperini on Wednesday March 25, 2020 @07:40AM (#22683650)
I would name that algorithm "inside-out" instead of "right-left" if my understanding of its behavior is correct.
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Wednesday March 25, 2020 @01:33PM (#22686698)
Aren't you supposed to treat multiple array or pointers as a group?
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @10:02PM (#22681327)
The fact that it's wrong if you try to generalize it beyond the examples given?
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @11:53PM (#22681807)
Does it? Here's one that I grabbed from cdecl.org:

  char * const (*(* const bar)[5])(int )
And its translation:

  declare bar as const pointer to array 5 of pointer to function (int) returning const pointer to char
This seems like what I'd get from the spiral technique.