Page MenuHomeFreeBSD

sys/limits.h: add C23 _WIDTH macros
AcceptedPublic

Authored by fuz on Wed, Nov 19, 1:02 PM.

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 Passed
Unit
No Test Coverage
Build Status
Buildable 68738
Build 65621: arc lint + arc unit

Event Timeline

fuz requested review of this revision.Wed, Nov 19, 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.Wed, Nov 19, 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.