|
|
Log in / Subscribe / Register

C: New operators

C: New operators

Posted May 4, 2026 0:53 UTC (Mon) by alx.manpages (subscriber, #145117)
Parent article: GCC 16.1 released

On the C side of things, there are three new operators: _Countof(), _Maxof(), and _Minof() (disclaimer: I added them).

_Countof() is the usual ARRAY_SIZE(), but slightly more powerful with VLAs. (And it might become even more powerful in the future.)

_Maxof() and _Minof() return the maximum and minimum representable values of the input type.


to post comments

C: New operators

Posted May 4, 2026 12:55 UTC (Mon) by adobriyan (subscriber, #30858) [Link] (1 responses)

> _Maxof(), and _Minof()

Thanks!

Kernel's type_min/type_max macros aren't the worst w.r.t of readability but still...

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/...

C: New operators

Posted May 4, 2026 13:56 UTC (Mon) by alx.manpages (subscriber, #145117) [Link]

> > _Maxof(), and _Minof()
>
> Thanks!

You're welcome!

Sadly, Clang seems to refuse implementing these until enough users ask them to do it. They don't think it's useful.

> Kernel's type_min/type_max macros aren't the worst w.r.t of readability but still...
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/...

Yup, especially, when the compiler already has that information, it doesn't make much sense to have to write that monster. An off-by-one bug or some UB in that macro would be difficult to find. In a project as large as the kernel, we'd probably notice, because it would break many places, but in smaller projects that only use it in a few places, UB could go unnoticed.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds