-
Notifications
You must be signed in to change notification settings - Fork 254
lib/, src/, tests/: Use the standard countof() instead of our NITEMS()
#1259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
countof() instead of out NITEMS()
countof() instead of out NITEMS()countof() instead of our NITEMS()
4d2bec3 to
2efe549
Compare
|
Note: GCC hasn't yet merged the patches implementing |
2efe549 to
e12ab0f
Compare
Aaaaand, done! GCC has merged my patches implementing |
35c87a1 to
bf02a07
Compare
countof() is the name blessed by the C Committee for ISO C2y. Use it if available, and define it if not. countof() will be provided by GCC 16 and Clang 21. This is mostly a scripted change: $ grep -rl NITEMS | xargs sed -i s/NITEMS/countof/; Apart from the scripted changes, I've adjusted white-space alignment, and of course the definition at "lib/sizeof.h". Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf#subsubsection.0.6.5.4.5> Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf#section.0.7.21> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will allow us to eventually get rid of must_be_array(), once we make sure countof() is safe. Signed-off-by: Alejandro Colomar <alx@kernel.org>
The error works as well as the magic macro, and we get cleaner code. Plus, very soon we'll get the countof() operator from GCC 16 and Clang 21, which doesn't even need this diagnostic to work safely. Signed-off-by: Alejandro Colomar <alx@kernel.org>
The macros that remain in "must_be.h" really belong in "typetraits.h". Move them there, and remove "must_be.h". Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
bf02a07 to
8cbd0e7
Compare
countof()is the name blessed by the C Committee for this macro in ISO C2y. Use it if available, and define it if not.countof()will be provided by GCC 16 and Clang 21.This is mostly a scripted change:
Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf#subsubsection.0.6.5.4.5
Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf#section.0.7.21
Revisions:
v1b
v2
countof()instead of its pattern.v2b
v2c
v2d
v2e
v2f