c2compiler icon indicating copy to clipboard operation
c2compiler copied to clipboard

Compiler: accept lists of declarations

Open chqrlie opened this issue 6 months ago • 2 comments

  • accept commas in variable declarations and struct member definitions
  • type must not be a pointer type nor an array type
  • add tests

chqrlie avatar Jun 16 '25 23:06 chqrlie

I'm still in unsure about this, is:

u32 x = 1, y = 2; so much better than:

u32 x = 1;
u32 y = 2;

I think it just makes the code less readable. Then people want to do this inside if/while declaration and so on. Also you need a lot of new rules (no pointers, arrays, etc). The goal is NOT to copy all features C has..

bvdberg avatar Jun 17 '25 09:06 bvdberg

I'm still in unsure about this, is:

u32 x = 1, y = 2; so much better than:

u32 x = 1;
u32 y = 2;

I think it just makes the code less readable. Then people want to do this inside if/while declaration and so on. Also you need a lot of new rules (no pointers, arrays, etc). The goal is NOT to copy all features C has..

I would not think in terms of much better, u32 x = 1, y = 2; is less readable than separate definitions, but if one needs to define 10 uninitialized variables x0 to x9, spreading that on 10 lines consumes vertical space for no benefit. Supporting both and letting the programmers choose what is most appropriate for their code seems common sense to me.

if and while conditions reject multiple definitions explicitly.

The reason for rejecting multiple definitions of pointers and arrays is semantic: char* p, q; would have a different meaning in C and C2, and this change would make the definition even more confusing.

chqrlie avatar Jun 17 '25 09:06 chqrlie

yes nice!

bvdberg avatar Jun 20 '25 14:06 bvdberg