casaroli opened a new pull request, #21571: URL: https://github.com/apache/nuttx/pull/21571
## Summary POSIX (XSI) defines `LONG_BIT` and `WORD_BIT` in `<limits.h>`: the number of bits in a `long` and in an `int`. Programs use them to size bit masks and bit arrays. NuttX does not define them, so such a program does not compile. This PR defines both in `include/limits.h`. The values come from `LONG_MAX` and `INT_MAX` of the architecture: 32 or 64 for `LONG_BIT`, 16 or 32 for `WORD_BIT`. They work in `#if`. ## Impact Two new macros in a public header; no code changes. The values are right for ILP32, LP64 and the targets with a 16-bit `int` (AVR, z80, z180, z8, M16C, HC12 without `__INT__ == 32`). No architecture header gives a 24-bit `INT_MAX`, so there is no 24 case. arch/z80/include/ez80/limits.h gives `INT_MAX` 32767 although `int` is 24 bits there, so `WORD_BIT` is 16 on ez80, as that `INT_MAX` gives. Nothing in nuttx or nuttx-apps defines these names. No Documentation change. ## Testing Test program `limitsbit.c`: `LONG_BIT == sizeof(long) * CHAR_BIT`, `WORD_BIT == sizeof(int) * CHAR_BIT`, and both work in `#if`. On master it does not compile. - qemu-armv8a:knsh (kernel build, arm64, QEMU): master does not compile the test; this PR 3/3 PASS (`LONG_BIT` 64, `WORD_BIT` 32). ostest exits 0 on qemu-armv8a:knsh and qemu-armv8a:nsh. - mps2-an500:knsh (protected build, Cortex-M7, QEMU): 3/3 PASS (32/32). - SDCC 4.6.0 for z80 (z80sim:nsh headers, 16-bit `int`): a compile check asserts `LONG_BIT` 32 and `WORD_BIT` 16 in `#if` and against `sizeof`: it compiles, and it stops with `#error` when the expected value is wrong. - Build only, with `EXTRAFLAGS="-Wno-cpp -Werror"`: nucleo-f072rb:nsh (Cortex-M0), qemu-armv8a:nsh (arm64), mps2-an500:knsh (protected), rv-virt:pnsh64 (protected, RISC-V), esp32s3-devkit:nsh (Xtensa): all build with no compiler warning. `tools/checkpatch.sh -c -u -m -g origin/master..HEAD` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
