lang-c icon indicating copy to clipboard operation
lang-c copied to clipboard

DerivedDeclarator inconsistency

Open imihajlow opened this issue 2 years ago • 1 comments

Enum DerivedDeclarator combines pointer, array, and function declarators. However, pointer declarators in C behave differently from array and function declarators. Pointer declarators are considered in right-to-left order, but array declarators go from left to right. For example:

int * const * volatile a[2][4];

This declares a as (array 2 of (array 4 of (volatile pointer to (const pointer to (int))))), but the DerivedDeclarators will be provided in the following order: Pointer(const), Pointer(volatile), Array(2), Array(4).

When using this list of DerivedDeclarators to build C types, special care should be taken to apply pointers in one direction and when they end, apply the rest in reverse direction. It would be more convenient to have RTL declarators and LTR declarators separated in the AST type system.

This is only my wish and suggestion and not a bug report. Please feel free to reject this issue as "won't do" if it goes against the philosophy of your crate.

imihajlow avatar Dec 21 '23 19:12 imihajlow

Yes, I think it makes sense. Perhaps something like #45?

vickenty avatar Dec 21 '23 21:12 vickenty