Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Jakub Jelinek
On Wed, May 21, 2025 at 11:44:42PM +0200, Alejandro Colomar wrote: > Does this sound good? > > diff --git i/gcc/c/c-parser.cc w/gcc/c/c-parser.cc > index faa03c4903a2..733cb312341e 100644 > --- i/gcc/c/c-parser.cc > +++ w/gcc/c/c-parser.cc > @@ -78,16 +78,6 @@ along w

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Alejandro Colomar
Hi Jakub, On Wed, May 21, 2025 at 11:47:30PM +0200, Jakub Jelinek wrote: > > @@ -1747,6 +1737,8 @@ static struct c_expr c_parser_binary_expression > > (c_parser *, struct c_expr *, > > tree); > > static struct c_expr c_parser_cast_expr

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Alejandro Colomar
Hi Jakub, On Wed, May 21, 2025 at 11:31:05PM +0200, Alejandro Colomar wrote: > > > +#define c_parser_sizeof_expression(parser) > > > \ > > > +( > > > \ > > > + c_parser_sizeof_or_count

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Jakub Jelinek
On Wed, May 21, 2025 at 11:31:01PM +0200, Alejandro Colomar wrote: > The preexisting ones are not just the outermost ones. The preexisting > code was > > (in_sizeof >? "sizeof" >: (in_typeof ? "typeof" : "alignof"))); > > The only pattern I can find

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Alejandro Colomar
On Wed, May 21, 2025 at 11:36:56PM +0200, Alejandro Colomar wrote: > Hi Jakub, > > On Wed, May 21, 2025 at 11:12:07PM +0200, Jakub Jelinek wrote: > > > warning_at (loc, OPT_Wc___compat, > > > "defining type in %qs expression is invalid in C++", > > > (in_sizeof > > >

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Alejandro Colomar
Hi Jakub, On Wed, May 21, 2025 at 11:12:07PM +0200, Jakub Jelinek wrote: > > warning_at (loc, OPT_Wc___compat, > > "defining type in %qs expression is invalid in C++", > > (in_sizeof > > ? "sizeof" > > -: (in_typeof ? "typeof" : "alignof"))); >

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Alejandro Colomar
Hi Jakub, On Wed, May 21, 2025 at 11:12:07PM +0200, Jakub Jelinek wrote: > > * c-common.h: Add RID_COUNTOF. > > (enum rid): Add RID_COUNTOF. Okay. > > > (c_countof_type): New function prototype. > > * c-common.def (COUNTOF_EXPR): New tree. > > * c-common.cc > > (c_common_re

Re: [PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Jakub Jelinek
On Wed, May 21, 2025 at 11:01:31PM +0200, Alejandro Colomar wrote: > This operator is similar to sizeof but can only be applied to an array, > and returns its number of elements. > > FUTURE DIRECTIONS: > > - We should make it work with array parameters to functions, >and somehow magically re

[PATCH v24 1/3] c: Add _Countof operator

2025-05-21 Thread Alejandro Colomar
This operator is similar to sizeof but can only be applied to an array, and returns its number of elements. FUTURE DIRECTIONS: - We should make it work with array parameters to functions, and somehow magically return the number of elements of the array, regardless of it being really a poin