2 ms·
> You read strictly left to right That wouldn't play well with pointers to arrays and pointers to functions: int (*pa)[X]; // int(*)[X] pa; int (*fp)(
by bluetomcat 10y ago
> You read strictly left to right
That wouldn't play well with pointers to arrays and pointers to functions:
int (*pa)[X]; // int(*)[X] pa;
int (*fp)(void); // int(*)(void) fp;
Here is how I designed the type declaration syntax in my own language, Quaint (https://github.com/bbu/quaint-lang https://github.com/bbu/quaint-lang):
pa: ptr(int[3]); // int (*pa)[3]
fp: fptr(): int; // int (*fp)(void)
arr: int[5]; // int arr[5]
p: ptr(int); // int *p
pp: ptr(ptr(int)); // int **pp
arrp: ptr[5](int); // int *p[5]
You basically have the identifier first, and then a recursive expression which uses mostly function-call-like expressions in order to nest recursive types.