[PATCH 0/3] integer limit macro consolidation

Rasmus Villemoes ravi at prevas.dk
Thu Jul 3 13:37:27 CEST 2025


I was bitten by our limit macros not being usable in #if conditionals
when building a standalone app. It turns out that the work to fix that
had already been started by the inclusion of the mbedtls library, so
it's something that people do hit.

Let's finish the job by providing suitable limit macros for all three families:

- Standard C types, char, short, ...
- Kernel-style fixed-width types s8, u64, ...
- POSIX/C99 fixed-width types int16_t, uint32_t, ...

Please note that a naive approach like spelling out the full decimal
value for the constants doesn't really work, as there is no such thing
as a "negative integer constant". That is, doing

#define LLONG_MIN -9223372036854775808LL

would lead to the compiler complaining

  warning: integer constant is so large that it is unsigned

and the type of that LLONG_MIN would actually be "unsigned long long", so e.g.

#if LLONG_MIN >= 0
#warning "LLONG_MIN is not negative?"
#endif

would fire.

Rasmus Villemoes (3):
  move more limits from kernel.h to limits.h and standardize their
    definitions
  move limits for sNN/uNN types from kernel.h to limits.h
  limits.h: provide all limit macros for standard [u]intNN_t types

 include/limits.h       | 58 +++++++++++++++++++++++++++++++++++++++---
 include/linux/kernel.h | 26 -------------------
 include/stdint.h       |  2 +-
 3 files changed, 55 insertions(+), 31 deletions(-)

-- 
2.50.0



More information about the U-Boot mailing list