Page MenuHomeFreeBSD

sys/limits.h: add C23 _WIDTH macros
ClosedPublic

Authored by fuz on Nov 19 2025, 1:02 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Dec 26, 6:18 AM
Unknown Object (File)
Tue, Dec 23, 6:14 AM
Unknown Object (File)
Wed, Dec 10, 4:10 AM
Unknown Object (File)
Mon, Dec 8, 6:50 AM
Unknown Object (File)
Nov 29 2025, 4:12 PM
Unknown Object (File)
Nov 28 2025, 12:35 PM
Unknown Object (File)
Nov 28 2025, 10:17 AM
Unknown Object (File)
Nov 28 2025, 12:41 AM

Details

Summary

For compliance with IOS/IEC 9899:2024 ("C23").

These macros define the width in bits of the basic integer types.
Another new macro, BITINT_MAXWIDTH, is not yet included as I do not
understand what it should be set to. Perhaps it is compiler-specific.

We don't have a man page for <limits.h>, so no docs for now.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

fuz requested review of this revision.Nov 19 2025, 1:02 PM

Approved

sys/sys/limits.h
72

This looks wrong, but after reading https://github.com/llvm/llvm-project/issues/117348 it's more clear. Your comment could be clearer though.

This revision is now accepted and ready to land.Nov 19 2025, 3:04 PM
sys/sys/limits.h
72

The *_WIDTH macros describe the width of the type, not the width of the storage (for that there is sizeof). You can only store a single bit in a bool, so 1 is consistent with that. For other types, there can be differences if the type is represented with padding bits. For example, the MSP430X architecture has sizeof(int) == 32 but INT_WIDTH == 20, with 12 padding bits. I'll look into adding a limits(3) man page to document this more precisely.

sys/sys/limits.h
72

For example, the MSP430X architecture has sizeof(int) == 32 but INT_WIDTH == 20, with 12 padding bits.

That was supposed to be sizeof(int) == 4 with CHAR_BIT == 8.

This revision was automatically updated to reflect the committed changes.