On 12/05/25 17:53 +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 return the number of elements of the array,
  regardless of it being really a pointer.

gcc/ChangeLog:

        * doc/extend.texi: Document _Countof operator.

gcc/c-family/ChangeLog:

        * c-common.h
        * c-common.def
        * c-common.cc (c_countof_type): Add _Countof operator.

gcc/c/ChangeLog:

        * c-tree.h
        (c_expr_countof_expr, c_expr_countof_type)
        * c-decl.cc
        (start_struct, finish_struct)
        (start_enum, finish_enum)
        * c-parser.cc
        (c_parser_sizeof_expression)
        (c_parser_countof_expression)
        (c_parser_sizeof_or_countof_expression)
        (c_parser_unary_expression)
        * c-typeck.cc
        (build_external_ref)
        (record_maybe_used_decl)
        (pop_maybe_used)
        (is_top_array_vla)
        (c_expr_countof_expr, c_expr_countof_type):
        Add _Countof operator.

gcc/testsuite/ChangeLog:

        * gcc.dg/countof-compile.c
        * gcc.dg/countof-vla.c
        * gcc.dg/countof.c: Add tests for _Countof operator.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117025>
Link: <https://inbox.sourceware.org/gcc/m8s4oqy--...@tutanota.com/T/>
Link: 
<https://inbox.sourceware.org/gcc-patches/20240728141547.302478-1-...@kernel.org/T/#t>
Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3313.pdf>
Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3325.pdf>
Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3369.pdf>
Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3469.htm>
Link: <https://github.com/llvm/llvm-project/issues/102836>
Link: <https://thephd.dev/the-big-array-size-survey-for-c>
Link: <https://thephd.dev/the-big-array-size-survey-for-c-results>
Link: <https://stackoverflow.com/questions/37538/#57537491>
Suggested-by: Xavier Del Campo Romero <xavi....@tutanota.com>
Co-authored-by: Martin Uecker <uec...@tugraz.at>
Acked-by: "James K. Lowden" <jklow...@schemamania.org>

What does this Acked-by: indicate?

My guess would be that it indicates approval for the patch, but Jim is
not an approver for the C front end, so he can't approve this patch.
Does Acked-by: indicate something other than approval?  When it's
somebody who can't approve the patch, how is it different to
Reviewed-by:?

I'm not overjoyed by the idea of trailers that mean something in some
other project (e.g. the kernel) but are just co-opted to mean
something slightly (or completely) different in the GCC repo without
some kind of agreement from the community about what they mean *here*.

Signed-off-by: Alejandro Colomar <a...@kernel.org>
---
gcc/c-family/c-common.cc               |  26 +++++
gcc/c-family/c-common.def              |   3 +
gcc/c-family/c-common.h                |   2 +
gcc/c/c-decl.cc                        |  22 +++-
gcc/c/c-parser.cc                      |  59 +++++++---
gcc/c/c-tree.h                         |   4 +
gcc/c/c-typeck.cc                      | 115 +++++++++++++++++-
gcc/doc/extend.texi                    |  30 +++++
gcc/testsuite/gcc.dg/countof-compile.c | 130 +++++++++++++++++++++
gcc/testsuite/gcc.dg/countof-vla.c     |  51 ++++++++
gcc/testsuite/gcc.dg/countof.c         | 154 +++++++++++++++++++++++++
11 files changed, 572 insertions(+), 24 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/countof-compile.c
create mode 100644 gcc/testsuite/gcc.dg/countof-vla.c
create mode 100644 gcc/testsuite/gcc.dg/countof.c


Reply via email to