[libc-commits] [libc] [libc] Fix definition of `UINT_MAX` in limits.h (PR #95279)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Wed Jun 12 11:07:49 PDT 2024


jhuber6 wrote:

> What's the issue?
> 
> ```
> #define UINT_MAX (~0U)
> _Static_assert(UINT_MAX == 0xFFFFFFFF, "");
> ```
> 
> compiles.

It's explained in the summary, `~0U` is not seem as equal to `0xFFFFFFFF` by the preprocessor in https://godbolt.org/z/TrjaY1d8q. This causes the situation shown there where the preprocessor says it's not `0xFFFFFFFF` but the static assert says it is. I found this while compiling the `compiler-rt` which checks exactly this, furthermore this is how both GNU and Clang's resource headers seem to do it.

https://github.com/llvm/llvm-project/pull/95279


More information about the libc-commits mailing list